PrinterTemplate.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\Printer\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_printer_template}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 平台id
  10. * @property int $head_info 头部信息
  11. * @property int $pickup_code 自提码
  12. * @property string $goods_info 商品信息
  13. * @property int $price_info 商品金额
  14. * @property int $remarks_info 备注
  15. * @property string $mall_info 商城信息
  16. * @property string $qrcode_url 二维码地址
  17. * @property string $bottom_info 底部信息
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at 添加时间戳
  20. * @property int $updated_at 更新时间戳
  21. */
  22. class PrinterTemplate extends \common\models\base\BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_printer_template}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'head_info', 'pickup_code', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['name','ticket_nam'], 'string', 'max' => 32],
  39. [['mall_info', 'remarks_info', 'buyer_info','goods_info','price_info'], 'string', 'max' => 48],
  40. [['qrcode_url', 'bottom_info'], 'string', 'max' => 360],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => '商城 ID',
  51. 'name' => '打印机名称',
  52. 'ticket_nam' => '小票名字',
  53. 'head_info' => '头部信息',
  54. 'pickup_code' => '头部信息',
  55. 'goods_info' => '商品信息',
  56. 'price_info' => '商品金额',
  57. 'buyer_info' => '买家信息',
  58. 'remarks_info' => '备注',
  59. 'mall_info' => '商城信息',
  60. 'qrcode_url' => '二维码地址',
  61. 'bottom_info' => '底部信息',
  62. 'status' => '状态[-1:删除;0:禁用;1启用]',
  63. 'created_at' => 'Created At',
  64. 'updated_at' => 'Updated At',
  65. ];
  66. }
  67. /**
  68. * 获取商城全部打印机模板
  69. * @author huangpei
  70. * @param int $mall_id
  71. * @return array
  72. */
  73. public static function getTemplateAllByMallId($mall_id){
  74. $params = [
  75. 'select' => ['id','name'],
  76. 'where' => [['=', 'mall_id', $mall_id],['<>','status',StatusEnum::DELETE]],
  77. 'order' => 'id desc'
  78. ];
  79. $query = self::find();
  80. self::paramPack($params,$query);
  81. return $query->asArray()->all();
  82. }
  83. /**
  84. * 保存数据
  85. * @author huangpei
  86. * @param array $params
  87. * @author huangpei
  88. * @return bool|object
  89. */
  90. public static function setData($params){
  91. try{
  92. if(!empty($params['id'])){
  93. $model = self::findOne(['id' => $params['id']]);
  94. if (empty($model) || $model->status == StatusEnum::DELETE) throw new \Exception('模板不存在或者已删除');
  95. }else{
  96. $model = new self();
  97. }
  98. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  99. return $model;
  100. }catch (\Exception $e) {
  101. self::$static_error = $e->getMessage();
  102. return false;
  103. }
  104. }
  105. }