Log.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Printer\common\models;
  3. use common\models\base\BaseActiveRecord;
  4. use PHPUnit\Util\Exception;
  5. /**
  6. * This is the model class for table "addons_printer_log".
  7. *
  8. * @property int $id ID
  9. * @property int $mch_id 多商户id,0表示商城订单
  10. * @property int $store_id 门店id
  11. * @property int $mall_id 商城id
  12. * @property int $order_id 订单id
  13. * @property int $type 打印类型,1: 下单,2: 支付,3: 确认收货,4: 后台
  14. * @property int $status 打印状态,0: 失败,1: 成功
  15. * @property int $msg 备注信息
  16. * @property int $created_at 创建时间
  17. * @property int $updated_at 上次更新数据时间
  18. */
  19. class Log extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_printer_log}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mch_id', 'store_id', 'mall_id', 'order_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
  35. [['msg'], 'string'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mch_id' => '多商户id,0表示商城订单',
  46. 'store_id' => '门店id',
  47. 'mall_id' => '商城id',
  48. 'order_id' => '订单id',
  49. 'type' => '打印类型,1: 下单,2: 支付,3: 确认收货,4: 后台',
  50. 'status' => '打印状态,0: 失败,1: 成功',
  51. 'msg' => '备注信息',
  52. 'created_at' => '创建时间',
  53. 'updated_at' => '上次更新数据时间',
  54. ];
  55. }
  56. /**
  57. * 保存数据
  58. * @param array $params
  59. * @return bool|PrintLog
  60. */
  61. public static function setData(array $params)
  62. {
  63. try {
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. empty($fail_counts) ? $param['status'] = 1 : $param['status'] = 2;
  67. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  68. return $model;
  69. } catch (Exception $e) {
  70. self::$static_error = $e->getMessage();
  71. return false;
  72. }
  73. }
  74. /**
  75. * 获取订单日志数据
  76. */
  77. public static function getOrderAction(array $cond = [], array $with = [], bool $is_array = true, string $select = '*')
  78. {
  79. $default_cond = [];
  80. $cond = array_merge($default_cond, $cond);
  81. $query = self::find()->select($select);
  82. self::paramPack(['where' => $cond, 'with' => $with], $query);
  83. $data = $query->orderBy('id desc')->asArray($is_array)->all();
  84. return $data;
  85. }
  86. }