| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%agent_front_staff_operate_log}}".
- *
- * @property integer $id
- * @property integer $staff_id
- * @property integer $front_agent_admin_id
- * @property integer $operate_type
- * @property integer $type_id
- * @property string $desc
- * @property integer $is_driver
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $updated_at
- */
- class AgentFrontStaffOperateLog extends \yii\db\ActiveRecord
- {
- /**
- * 操作类型:商品收货
- */
- const OPERATE_TYPE_GOODS_CONFIRM = 0;
- /**
- * 操作类型:商品分拣
- */
- const OPERATE_TYPE_GOODS_SORTING = 1;
- /**
- * 操作类型:线路修改
- */
- const OPERATE_TYPE_SET_ROUTE = 2;
- const OPERATE_TYPE_ARR = [
- self::OPERATE_TYPE_GOODS_CONFIRM,
- self::OPERATE_TYPE_GOODS_SORTING,
- self::OPERATE_TYPE_SET_ROUTE,
- ];
- public static $operateTypeDesc = [
- self::OPERATE_TYPE_GOODS_CONFIRM => '商品收货',
- self::OPERATE_TYPE_GOODS_SORTING => '商品分拣',
- self::OPERATE_TYPE_SET_ROUTE => '线路修改',
- ];
- const IS_DRIVER_NO = 0;
- const IS_DRIVER_YES = 1;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%agent_front_staff_operate_log}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'staff_id', 'operate_type', 'created_at', 'updated_at', 'is_delete', 'type_id', 'front_agent_admin_id', 'is_driver'], 'integer'],
- [['desc'], 'string']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'staff_id' => '绑定用户(平台用户)',
- 'operate_type' => '操作类型:0=供货商收货;1=商品分拣;2=线路修改;',
- 'type_id' => '操作id 如:收货订单id、拣货订单id、线路id',
- 'desc' => '操作内容',
- 'is_driver' => '是否是司机操作',
- 'is_delete' => '',
- 'created_at' => '',
- 'updated_at' => '',
- ];
- }
- /**
- * 添加操作日志
- * @param $operate_type integer 操作类型
- * @param $staff_id integer 仓库员工ID
- * @param $desc string 操作内容
- * @return bool
- */
- public static function addOperateLog($operate_type, $staff_id, $front_agent_admin_id, $type_id, $desc = '', $is_driver = self::IS_DRIVER_NO)
- {
- try {
- if (!in_array($operate_type, self::OPERATE_TYPE_ARR)) {
- throw new \Exception('操作类型错误');
- }
- $operate_log = new AgentFrontStaffOperateLog();
- $operate_log->operate_type = $operate_type;
- $operate_log->front_agent_admin_id = $front_agent_admin_id;
- $operate_log->type_id = $type_id;
- $operate_log->desc = $desc;
- $operate_log->is_driver = $is_driver;
- $operate_log->staff_id = $staff_id;
- if (!$operate_log->save()) {
- throw new \Exception(implode(';', array_values($operate_log->firstErrors)));
- };
- return true;
- } catch (\Exception $e) {
- debug_log([
- 'message' => $e->getMessage(),
- 'line' => $e->getLine()
- ], 'agentFrontStaffLog.log');
- return false;
- }
- }
- }
|