| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace addons\Printer\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_printer_template}}".
- *
- * @property int $id
- * @property int $mall_id 平台id
- * @property int $head_info 头部信息
- * @property int $pickup_code 自提码
- * @property string $goods_info 商品信息
- * @property int $price_info 商品金额
- * @property int $remarks_info 备注
- * @property string $mall_info 商城信息
- * @property string $qrcode_url 二维码地址
- * @property string $bottom_info 底部信息
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- */
- class PrinterTemplate extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_printer_template}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'head_info', 'pickup_code', 'status', 'created_at', 'updated_at'], 'integer'],
- [['name','ticket_nam'], 'string', 'max' => 32],
- [['mall_info', 'remarks_info', 'buyer_info','goods_info','price_info'], 'string', 'max' => 48],
- [['qrcode_url', 'bottom_info'], 'string', 'max' => 360],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城 ID',
- 'name' => '打印机名称',
- 'ticket_nam' => '小票名字',
- 'head_info' => '头部信息',
- 'pickup_code' => '头部信息',
- 'goods_info' => '商品信息',
- 'price_info' => '商品金额',
- 'buyer_info' => '买家信息',
- 'remarks_info' => '备注',
- 'mall_info' => '商城信息',
- 'qrcode_url' => '二维码地址',
- 'bottom_info' => '底部信息',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 获取商城全部打印机模板
- * @author huangpei
- * @param int $mall_id
- * @return array
- */
- public static function getTemplateAllByMallId($mall_id){
- $params = [
- 'select' => ['id','name'],
- 'where' => [['=', 'mall_id', $mall_id],['<>','status',StatusEnum::DELETE]],
- 'order' => 'id desc'
- ];
- $query = self::find();
- self::paramPack($params,$query);
- return $query->asArray()->all();
- }
- /**
- * 保存数据
- * @author huangpei
- * @param array $params
- * @author huangpei
- * @return bool|object
- */
- public static function setData($params){
- try{
- if(!empty($params['id'])){
- $model = self::findOne(['id' => $params['id']]);
- if (empty($model) || $model->status == StatusEnum::DELETE) throw new \Exception('模板不存在或者已删除');
- }else{
- $model = new self();
- }
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- }catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|