| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * @package merchant
- * Author: Qinii
- * Date: 2020/5/6
- * Time: 14:21
- */
- namespace app\common\dao\store\shipping;
- use app\common\model\store\shipping\ShippingTemplate;
- use app\entity\data\shipping\ShippingTemplateEntity;
- use think\facade\Db;
- use app\common\dao\BaseDao;
- use app\common\model\store\shipping\ShippingTemplate as model;
- class ShippingTemplateDao extends BaseDao
- {
- /**
- * @Author:Qinii
- * @Date: 2020/5/8
- * @return string
- */
- protected function getModel(): string
- {
- return model::class;
- }
- /**
- * @Author:Qinii
- * @Date: 2020/5/7
- * @param int $merId
- * @param array $where
- * @return mixed
- */
- public function search(int $merId,array $where)
- {
- $query = ($this->getModel()::getDB())->where('mer_id',$merId)->order('sort desc');
- if(isset($where['name']) && !empty($where['name']))
- $query->where('name','like','%'.$where['name'].'%');
- if(isset($where['type']) && !empty($where['type']))
- $query->where('type',$where['type']);
- return $query;
- }
- /**
- * 查询是否存在
- * @Author:Qinii
- * @Date: 2020/5/7
- * @param int $merId
- * @param $field
- * @param $value
- * @param null $except
- * @return bool
- */
- public function merFieldExists(int $merId, $field, $value, $except = null)
- {
- return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
- $query->where($field, '<>', $except);
- })->where('mer_id', $merId)->where($field, $value)->count() > 0;
- }
- /**
- * 关联删除
- * @Author:Qinii
- * @Date: 2020/5/7
- * @param int $id
- * @return int|void
- */
- public function delete(int $id)
- {
- $result = $this->getModel()::with(['free','region','undelives'])->find($id);
- $result->together(['free','region','undelives'])->delete();
- }
- /**
- * 批量删除
- * @Author:Qinii
- * @Date: 2020/5/8
- * @param int $id
- * @return mixed
- */
- public function batchRemove(int $id)
- {
- return ($this->getModel())::getDB()->where($this->getPk(),'in',$id)->delete();
- }
- public function getList($merId)
- {
- // return ($this->getModel())::getDB()->where('mer_id',$merId)->field('shipping_template_id,name')->select();
- $list = ($this->getModel())::getDB()->where('mer_id',$merId)->field('shipping_template_id,name')->select()->toArray();
- $default = ['shipping_template_id' => 105, 'name' => '默认包邮'];//默认
- array_unshift($list, $default);
- return $list;
- }
- /**
- * @param int $shippingTemplateId
- * @return \app\entity\CommonEntity
- */
- public function getShippingTemplateEntityByShippingTemplateId(int $shippingTemplateId): \app\entity\CommonEntity
- {
- $data = [];
- try {
- /** @var ShippingTemplate $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->where('shipping_template_id', '=', $shippingTemplateId)
- ->find();
- if (!empty($dataRes)) {
- $data = $dataRes->toArray();
- }
- } catch (\Exception $e) {
- }
- return ShippingTemplateEntity::newInstance($data);
- }
- }
|