PartsStockReload.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Exception;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. /**
  7. *产品库存申请记录
  8. */
  9. class PartsStockReload extends Model
  10. {
  11. use SoftDelete;
  12. protected $name = 'qingdongams_parts_stock_reload';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. protected $deleteTime = 'deletetime';
  19. protected $hidden = ['deletetime', 'updatetime'];
  20. public function getCreatetimeAttr($value)
  21. {
  22. return date('Y-m-d H:i', $value);
  23. }
  24. //创建人
  25. public function createStaff() {
  26. return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name,img');
  27. }
  28. //获取详情
  29. public function getPartsAttr($value){
  30. return json_decode($value,true);
  31. }
  32. //添加库存记录
  33. public static function addRecord($params)
  34. {
  35. $staff = Staff::info();
  36. if (!empty($staff)) {
  37. $params['create_staff_id'] = $staff->id;
  38. }
  39. $flow = Flow::getsteplist(Flow::PARTS_STATUS);
  40. $params['flow_id'] = $flow['flow_id'];
  41. $params['order_id'] = $flow['order_id'];
  42. if ($flow['status'] == 0) {//发起人自选
  43. if (empty($params['flow_staff_ids'])) {
  44. throw new Exception('审批人必须选择');
  45. }
  46. $params['flow_staff_ids'] = trim($params['flow_staff_ids']);
  47. } else {
  48. $params['flow_staff_ids'] = trim($flow['flow_staff_ids']);
  49. }
  50. $model = new self;
  51. // 调用当前模型对应的User验证器类进行数据验证
  52. $result = $model->allowField(true)->save($params);
  53. $lastId = $model->getLastInsID();
  54. if (false === $result) {
  55. // 验证失败 输出错误信息
  56. throw new Exception($model->getError());
  57. }
  58. if ($flow['status'] == 1) {//固定审批
  59. //发送审批通知
  60. Flow::sendStepRecord($flow,Flow::PARTS_STATUS, $lastId);
  61. } else {//发起人自选 依次审批
  62. $staff_id = explode(',', $params['flow_staff_ids'])[0];
  63. if ($staff_id) {
  64. ExamineRecord::addExaminse(ExamineRecord::PARTS_TYPE, $lastId, $staff_id);
  65. }
  66. }
  67. return $lastId;
  68. }
  69. }