<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                **思路:** 控制器:路由作用,基本訪問流程,定義返回數據格式 驗證碼:驗證提交的數據 模型:所有數據庫表的操作(按表建,一張表的操作盡量都在同一個文件里) service:公共的邏輯 **代碼:** 控制器 ?app\\admin\\controller\\config\\CardAgreement.php ``` <?php /* * @Author: yhy * @Date: 2023-01-06 09:43:23 * @FilePath: \backend-shop\app\admin\controller\config\CardAgreement.php * @Description: 卡項協議 控制器 * */ declare(strict_types=1); namespace app\admin\controller\config; use app\admin\controller\Controller; use app\admin\model\config\CardAgreement as CardAgreementModel; use app\admin\validate\config\CardAgreement as CardAgreementValidate; use think\App; class CardAgreement extends Controller { protected $model = null; public function __construct(App $app) { parent::__construct($app); $this->model = new CardAgreementModel(); } /** * 列表 * @return array * @throws \think\db\exception\DbException */ public function index() { $params = $this->postForm() ?? []; $list = $this->model->getList($params); return $this->renderSuccess(compact('list')); } /** * 添加 * @return array */ public function add() { $params = $this->postForm() ?? []; validate(CardAgreementValidate::class)->scene('add')->check($params); if ($this->model->add($params)) { return $this->renderSuccess('添加成功'); } return $this->renderError($this->model->getError() ?: '添加失敗'); } /** * 編輯 * @return array */ public function edit() { // 模板詳情 $params = $this->postForm() ?? []; validate(CardAgreementValidate::class)->scene('edit')->check($params); // 更新記錄 if ($this->model->edit($params)) { return $this->renderSuccess('更新成功'); } return $this->renderError($this->model->getError() ?: '更新失敗'); } /** * 獲取詳情記錄 * @return array */ public function detail() { $params = $this->postForm() ?? []; validate(CardAgreementValidate::class)->scene('detail')->check($params); $info = $this->model->detail((int)$params['card_agreement_id']); return $this->renderSuccess(compact('info')); } /** * @description: 修改狀態 * @return {*} */ public function checkStatus() { $params = $this->postForm() ?? []; validate(CardAgreementValidate::class)->scene('status')->check($params); if ($this->model->checkStatus($params)) { return $this->renderSuccess('修改成功'); } return $this->renderError($this->model->getError() ?: '修改失敗'); } /** * 刪除 * @return array */ public function delete() { $params = $this->postForm() ?? []; validate(CardAgreementValidate::class)->scene('delete')->check($params); if (!$this->model->omit($params)) { return $this->renderError($this->model->getError() ?: '刪除失敗'); } return $this->renderSuccess('刪除成功'); } } ``` 驗證器 app\\admin\\validate\\config\\CardAgreement.php ``` <?php /* * @Author: yhy * @Date: 2023-01-06 09:43:39 * @FilePath: \backend-shop\app\admin\validate\config\CardAgreement.php * @Description: 卡項協議 驗證器 * */ namespace app\admin\validate\config; use app\admin\model\config\CardAgreement as CardAgreementModel; use app\admin\model\Store; use think\Validate as V; class CardAgreement extends V { //當前驗證規則 protected $rule = [ 'card_agreement_id|ID' => 'require|integer', 'name|名稱' => 'require|min:2|max:20|checkName', 'type|類型' => 'require|in:10,20,30,40|integer', 'content|協議內容' => 'require|min:1|max:10000', 'status|狀態' => 'require|in:10,20|integer', 'store_ids|適用商城' => 'require|array|checkStoreList', 'search|搜索' => 'min:1|max:20', ]; //驗證場景定義 protected $scene = [ 'add' => ['name','type','content','status','store_ids'], 'edit' => ['card_agreement_id','name','type','content','status','store_ids'], 'detail' => ['card_agreement_id'], 'delete' => ['card_agreement_id'], 'status' => ['card_agreement_id','status'], 'list' => ['search'], ]; // 自定義驗證規則 protected function checkName($value, $rule, $data=[]) { if (!empty($data['card_agreement_id'])) { $bool = CardAgreementModel::where('card_agreement_id','<>',$data['card_agreement_id']) ->where('name','=',$value) ->find(); } else { $bool = CardAgreementModel::where('name','=',$value) ->find(); } if ($bool) { return '名稱已存在'; } return true; } /** * @description: 驗證商城id和區域id * @param {*} $value * @return {*} */ public function checkStoreList($value) { //數據處理 if(empty($value)){ return '請選擇商城'; } //判定每個商城是否存在 if(count($value) != Store::inNum($value)){ return '部分商城已經不存在'; } return true; } } ``` 模型 app\\admin\\model\\config\\CardAgreement.php ``` <?php /* * @Author: yhy * @Date: 2023-01-06 09:43:33 * @FilePath: \backend-shop\app\admin\model\config\CardAgreement.php * @Description: 卡項協議 model * */ declare (strict_types=1); namespace app\admin\model\config; use app\common\model\config\CardAgreement as CardAgreementCommon; use think\facade\Db; class CardAgreement extends CardAgreementCommon { /** * 獲取列表記錄 * @param array $params * @return \think\Paginator * @throws \think\db\exception\DbException */ public function getList(array $params = []): \think\Paginator { // 檢索查詢條件 $filter = $this->getFilter($params); // 查詢列表數據 return $this->where($filter) ->with(['card_agreement_store_rel.store']) ->hidden(['card_agreement_store_rel.store']) ->order(['create_time' => 'desc']) ->paginate(15); } /** * 檢索查詢條件 * @param array $params * @return array */ private function getFilter(array $params = []): array { $allowFilter = ['search',]; // 默認查詢條件 $params = $this->setQueryDefaultValue($params, ['search' => '']); // 檢索查詢條件 $filter[] = ['is_delete','=',self::IS_DELETE_NO]; foreach($params as $key=>$value){ if(!in_array($key,$allowFilter) || (empty($value) && $value!=0)) continue; if($key == 'search'){ !empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"]; }else{ $filter[] = [$key,'=',$value]; } } return $filter; } /** * 添加新記錄 * @param array $params * @return bool|false */ public function add(array $params): bool { Db::startTrans(); try { //添加協議表 $this->allowField(['name','type','content','status'])->save($params); //添加與商城關聯 $card_agreement_store_rel_model = new CardAgreementStoreRel(); $card_agreement_store_rel_model->increased($params['store_ids'],(int)$this->card_agreement_id); // 提交事務 Db::commit(); } catch (\Exception $e) { $this->setError($e->getMessage()); // 回滾事務 Db::rollback(); return false; } return true; } /** * 更新記錄 * @param array $params * @return bool */ public function edit(array $params): bool { $model = $this->findOne((int)$params['card_agreement_id']); if($model){ Db::startTrans(); try { //修改協議表 $model->allowField(['name','type','content','status'])->save($params); //添加與商城關聯 $card_agreement_store_rel_model = new CardAgreementStoreRel(); $card_agreement_store_rel_model->where('card_agreement_id',$params['card_agreement_id'])->delete(); $card_agreement_store_rel_model->increased($params['store_ids'],(int)$params['card_agreement_id']); // 提交事務 Db::commit(); } catch (\Exception $e) { $this->setError($e->getMessage()); // 回滾事務 Db::rollback(); return false; } return true; } return false; } /** * @description: 詳情 * @param {int} $id * @return {*} */ public function detail(int $id) { $model= $this->where('is_delete',self::IS_DELETE_NO) ->with(['card_agreement_store_rel.store']) ->hidden(['card_agreement_store_rel.store']) ->find($id); if(!$model){ $this->setError('數據不存在'); return false; } return $model; } /** * @description: 查詢是否存在數據 * @param {*} $id * @return {*} */ public function findOne(int $id) { $model = $this->where('is_delete',self::IS_DELETE_NO)->find($id); if(!$model){ $this->setError('數據不存在'); return false; } return $model; } /** * @description: 修改狀態 * @param {*} $params * @return {*} */ public function checkStatus($params) { //判定數據是否存在 $model = $this->findOne((int)$params['card_agreement_id']); //修改狀態 return $model && $model->allowField(['status'])->save($params); } /** * @description: 刪除 * @param {array} $params * @return {*} */ public function omit(array $params) { $model = $this->findOne((int)$params['card_agreement_id']); if($model){ Db::startTrans(); try { //刪除協議 $model->is_delete = self::IS_DELETE_YES; $model->save(); //刪除 協議和商城關系 CardAgreementStoreRel::where('card_agreement_id',$params['card_agreement_id'])->delete(); // 提交事務 Db::commit(); } catch (\Exception $e) { $this->setError($e->getMessage()); // 回滾事務 Db::rollback(); return false; } return true; } return false; } } ``` 公共模型 app\\common\\model\\config\\CardAgreement.php ``` <?php /* * @Author: yhy * @Date: 2023-01-06 09:43:45 * @FilePath: \backend-shop\app\common\model\config\CardAgreement.php * @Description: 卡項協議 模型 * */ declare (strict_types=1); namespace app\common\model\config; use app\common\model\Base; use think\model\relation\HasMany; class CardAgreement extends Base { // 定義表名 protected $name = 'card_agreement'; // 定義主鍵 protected $pk = 'card_agreement_id'; //類型:10次卡20充值卡30折扣卡40專項卡 const CARD_TYPE_NUM = 10; const CARD_TYPE_RECHARGE = 20; const CARD_TYPE_DISCOUNT = 30; const CARD_TYPE_SPECIAL = 40; public static $cardTypeData = [ self::CARD_TYPE_NUM => ["value" => self::CARD_TYPE_NUM,"text" => "次卡"], self::CARD_TYPE_RECHARGE => ["value" => self::CARD_TYPE_RECHARGE,"text" => "充值卡"], self::CARD_TYPE_DISCOUNT => ["value" => self::CARD_TYPE_DISCOUNT,"text" => "折扣卡"], self::CARD_TYPE_SPECIAL => ["value" => self::CARD_TYPE_SPECIAL,"text" => "專項卡"], ]; public function getTypeAttr($value): array { return self::$cardTypeData[$value]; } /** * @description: 修改器:內容 * @param {*} $value * @return {*} */ public function getContentAttr($value) { return htmlspecialchars_decode($value); } /** * @description: 關聯適用商城 * @return {*} */ public function CardAgreementStoreRel():HasMany { return $this->hasMany(CardAgreementStoreRel::class,'card_agreement_id','card_agreement_id'); } } ``` 邏輯層 app\\admin\\service\\Cache.php ``` <?php // +---------------------------------------------------------------------- // | 螢火商城系統 [ 致力于通過產品和服務,幫助商家高效化開拓市場 ] // +---------------------------------------------------------------------- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved. // +---------------------------------------------------------------------- // | Licensed 這不是一個自由軟件,不允許對程序代碼以任何形式任何目的的再發行 // +---------------------------------------------------------------------- // | Author: 螢火科技 <admin@yiovo.com> // +---------------------------------------------------------------------- declare (strict_types=1); namespace app\admin\service; use app\common\service\BaseService; use think\facade\Cache as CacheDriver; /** * 清理緩存 * Class Cache */ class Cache extends BaseService { // 緩存驅動句柄 /** @var $CacheDriver \think\Cache */ private $cache; /** * 構造方法 * Cache constructor. */ public function initialize() { // 實例化緩存驅動 $this->cache = CacheDriver::instance(); } /** * 刪除緩存 * @param $data * @return bool */ public function rmCache($data) { // 數據緩存 if (in_array('data', $data['item'])) { // 強制模式 $isForce = isset($data['isForce']) && (bool)$data['isForce']; // 清除緩存 $isForce ? $this->cache->clear() : $this->cache->tag('cache')->clear(); } // 臨時文件 if (in_array('temp', $data['item'])) { $paths = [ 'temp' => web_path() . 'temp/', 'runtime' => runtime_root_path() . 'image/' ]; foreach ($paths as $path) { $this->deleteFolder($path); } } return true; } /** * 遞歸刪除指定目錄下所有文件 * @param $path * @return void */ private function deleteFolder($path): void { if (!is_dir($path)) { return; } // 掃描一個文件夾內的所有文件夾和文件 foreach (scandir($path) as $val) { // 排除目錄中的.和.. if (!in_array($val, ['.', '..', '.gitignore'])) { // 如果是目錄則遞歸子目錄,繼續操作 if (is_dir($path . $val)) { // 子目錄中操作刪除文件夾和文件 $this->deleteFolder($path . $val . '/'); // 目錄清空后刪除空文件夾 rmdir($path . $val . '/'); } else { // 如果是文件直接刪除 unlink($path . $val); } } } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看