AgentFrontStaffOperateLog.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;
  4. use yii\db\ActiveRecord;
  5. /**
  6. * This is the model class for table "{{%agent_front_staff_operate_log}}".
  7. *
  8. * @property integer $id
  9. * @property integer $staff_id
  10. * @property integer $front_agent_admin_id
  11. * @property integer $operate_type
  12. * @property integer $type_id
  13. * @property string $desc
  14. * @property integer $is_driver
  15. * @property integer $is_delete
  16. * @property integer $created_at
  17. * @property integer $updated_at
  18. */
  19. class AgentFrontStaffOperateLog extends \yii\db\ActiveRecord
  20. {
  21. /**
  22. * 操作类型:商品收货
  23. */
  24. const OPERATE_TYPE_GOODS_CONFIRM = 0;
  25. /**
  26. * 操作类型:商品分拣
  27. */
  28. const OPERATE_TYPE_GOODS_SORTING = 1;
  29. /**
  30. * 操作类型:线路修改
  31. */
  32. const OPERATE_TYPE_SET_ROUTE = 2;
  33. const OPERATE_TYPE_ARR = [
  34. self::OPERATE_TYPE_GOODS_CONFIRM,
  35. self::OPERATE_TYPE_GOODS_SORTING,
  36. self::OPERATE_TYPE_SET_ROUTE,
  37. ];
  38. public static $operateTypeDesc = [
  39. self::OPERATE_TYPE_GOODS_CONFIRM => '商品收货',
  40. self::OPERATE_TYPE_GOODS_SORTING => '商品分拣',
  41. self::OPERATE_TYPE_SET_ROUTE => '线路修改',
  42. ];
  43. const IS_DRIVER_NO = 0;
  44. const IS_DRIVER_YES = 1;
  45. /**
  46. * @inheritdoc
  47. */
  48. public static function tableName()
  49. {
  50. return '{{%agent_front_staff_operate_log}}';
  51. }
  52. public function behaviors()
  53. {
  54. return [
  55. [
  56. 'class' => TimestampBehavior::class,
  57. 'attributes' => [
  58. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
  59. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  60. ]
  61. ]
  62. ];
  63. }
  64. /**
  65. * @inheritdoc
  66. */
  67. public function rules()
  68. {
  69. return [
  70. [['id', 'staff_id', 'operate_type', 'created_at', 'updated_at', 'is_delete', 'type_id', 'front_agent_admin_id', 'is_driver'], 'integer'],
  71. [['desc'], 'string']
  72. ];
  73. }
  74. public function attributeLabels()
  75. {
  76. return [
  77. 'id' => '',
  78. 'staff_id' => '绑定用户(平台用户)',
  79. 'operate_type' => '操作类型:0=供货商收货;1=商品分拣;2=线路修改;',
  80. 'type_id' => '操作id 如:收货订单id、拣货订单id、线路id',
  81. 'desc' => '操作内容',
  82. 'is_driver' => '是否是司机操作',
  83. 'is_delete' => '',
  84. 'created_at' => '',
  85. 'updated_at' => '',
  86. ];
  87. }
  88. /**
  89. * 添加操作日志
  90. * @param $operate_type integer 操作类型
  91. * @param $staff_id integer 仓库员工ID
  92. * @param $desc string 操作内容
  93. * @return bool
  94. */
  95. public static function addOperateLog($operate_type, $staff_id, $front_agent_admin_id, $type_id, $desc = '', $is_driver = self::IS_DRIVER_NO)
  96. {
  97. try {
  98. if (!in_array($operate_type, self::OPERATE_TYPE_ARR)) {
  99. throw new \Exception('操作类型错误');
  100. }
  101. $operate_log = new AgentFrontStaffOperateLog();
  102. $operate_log->operate_type = $operate_type;
  103. $operate_log->front_agent_admin_id = $front_agent_admin_id;
  104. $operate_log->type_id = $type_id;
  105. $operate_log->desc = $desc;
  106. $operate_log->is_driver = $is_driver;
  107. $operate_log->staff_id = $staff_id;
  108. if (!$operate_log->save()) {
  109. throw new \Exception(implode(';', array_values($operate_log->firstErrors)));
  110. };
  111. return true;
  112. } catch (\Exception $e) {
  113. debug_log([
  114. 'message' => $e->getMessage(),
  115. 'line' => $e->getLine()
  116. ], 'agentFrontStaffLog.log');
  117. return false;
  118. }
  119. }
  120. }