diff --git a/application/admin/controller/school/Message.php b/application/admin/controller/school/Message.php index abc2c8e..b0a03b6 100644 --- a/application/admin/controller/school/Message.php +++ b/application/admin/controller/school/Message.php @@ -28,6 +28,10 @@ class Message extends Backend $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("miniTypeList", $this->model->getMiniTypeList()); + + $this->view->assign("statusListJson", json_encode($this->model->getStatusList(), JSON_UNESCAPED_UNICODE)); + $this->view->assign("miniTypeListJson", json_encode($this->model->getMiniTypeList(), JSON_UNESCAPED_UNICODE)); + } diff --git a/application/admin/controller/school/classes/activity/Activity.php b/application/admin/controller/school/classes/activity/Activity.php index b57a1c5..ef291d2 100644 --- a/application/admin/controller/school/classes/activity/Activity.php +++ b/application/admin/controller/school/classes/activity/Activity.php @@ -77,11 +77,33 @@ class Activity extends Backend if ($this->request->request('keyField')) { return $this->selectpage(); } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + list($where, $sort, $order, $offset, $limit, $page, $alias, $bind, $excludearray) = $this->buildparams(null, null, ["has_expire"]); + + if (isset($excludearray['has_expire']['value']) && $excludearray['has_expire']['value']) { + $has_expire = $excludearray['has_expire']['value']; + $as = (new \app\common\model\school\classes\activity\Activity)->getWithAlisaName(); + switch ($has_expire) { + case '1': //查过期 + $expireWhere = [ + $as . '.end_time', '<=', time(), + ]; + break; + case '2': //查未过期 + $expireWhere = [ + $as . '.end_time', '>', time(), + ]; + break; + default: + } + + } else { + $expireWhere = [[]]; + } $list = $this->model ->with(['manystore','shop']) ->where($where) + ->where(...$expireWhere) ->order($sort, $order) ->paginate($limit); @@ -296,7 +318,7 @@ class Activity extends Backend foreach ($delete_spec_ids as $k=>$delete_spec){ -// (new \app\common\model\school\classes\activity\ActivityItem)->updateCheck($delete_spec["id"]); + (new \app\common\model\school\classes\activity\ActivityItem)->updateCheck($delete_spec["id"]); $delete_spec->delete(); } @@ -357,6 +379,10 @@ class Activity extends Backend foreach ($list as $item) { //删除课程规格 \app\common\model\school\classes\activity\ActivityItem::where("classes_activity_id",$item->id)->delete(); + //删除课程规格 + \app\common\model\school\classes\activity\ActivityItemAuth::where("classes_activity_id",$item->id)->delete(); + \app\common\model\school\classes\activity\ActivityAuth::where("classes_activity_id",$item->id)->delete(); + $count += $item->delete(); } diff --git a/application/admin/controller/school/classes/activity/ActivityAuth.php b/application/admin/controller/school/classes/activity/ActivityAuth.php index 2505e3f..1b25cf1 100644 --- a/application/admin/controller/school/classes/activity/ActivityAuth.php +++ b/application/admin/controller/school/classes/activity/ActivityAuth.php @@ -3,6 +3,14 @@ namespace app\admin\controller\school\classes\activity; use app\common\controller\Backend; +use app\common\model\school\classes\activity\order\Order; +use think\Db; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\Exception; +use think\exception\DbException; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 课程活动审核 @@ -17,11 +25,24 @@ class ActivityAuth extends Backend * @var \app\admin\model\school\classes\activity\ActivityAuth */ protected $model = null; + protected $itemmodel = null; + + protected $qSwitch = true; + protected $qFields = ["user_id","shop_id","manystore_id"]; + protected $success_auth = false; + protected $error_auth = false; + + //不用审核允许修改的字段 + protected $no_auth_fields = ['headimage','images','content',"price"]; + public function _initialize() { - parent::_initialize(); + $this->model = new \app\admin\model\school\classes\activity\ActivityAuth; + $this->itemmodel = new \app\admin\model\school\classes\activity\ActivityItemAuth(); + parent::_initialize(); + $this->view->assign("addressTypeList", $this->model->getAddressTypeList()); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("recommendList", $this->model->getRecommendList()); @@ -31,6 +52,14 @@ class ActivityAuth extends Backend $this->view->assign("authStatusList", $this->model->getAuthStatusList()); $this->view->assign("expirestatusList", $this->model->getExpirestatusList()); $this->view->assign("addTypeList", $this->model->getAddTypeList()); + + + + $this->getCity(); + $this->getAuthMsg(); + + $this->view->assign("itemStatusList", $this->itemmodel->getStatusList()); + $this->view->assign("sexList", $this->itemmodel->getSexList()); } @@ -56,16 +85,38 @@ class ActivityAuth extends Backend if ($this->request->request('keyField')) { return $this->selectpage(); } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + list($where, $sort, $order, $offset, $limit, $page, $alias, $bind, $excludearray) = $this->buildparams(null, null, ["has_expire"]); + + if (isset($excludearray['has_expire']['value']) && $excludearray['has_expire']['value']) { + $has_expire = $excludearray['has_expire']['value']; + $as = (new \app\common\model\school\classes\activity\ActivityAuth)->getWithAlisaName(); + switch ($has_expire) { + case '1': //查过期 + $expireWhere = [ + $as . '.end_time', '<=', time(), + ]; + break; + case '2': //查未过期 + $expireWhere = [ + $as . '.end_time', '>', time(), + ]; + break; + default: + } + + } else { + $expireWhere = [[]]; + } $list = $this->model - ->with(['activity','manystore','shop']) - ->where($where) - ->order($sort, $order) - ->paginate($limit); + ->with(['activity','manystore','shop']) + ->where($where) + ->where(...$expireWhere) + ->order($sort, $order) + ->paginate($limit); foreach ($list as $row) { - + $row->getRelation('activity')->visible(['id']); $row->getRelation('manystore')->visible(['nickname']); $row->getRelation('shop')->visible(['name','logo']); @@ -78,4 +129,344 @@ class ActivityAuth extends Backend return $this->view->fetch(); } + + protected function update_classes($classes_activity_id,$row=null){ + if($classes_activity_id && $row){ + $activity = \app\common\model\school\classes\activity\Activity::where("id",$classes_activity_id)->find(); + if($activity && in_array($row["auth_status"],[0,2])){ + $activity["classes_activity_auth_id"] = $row["id"]; + $activity->save(); + } + } + } + + + + + + + protected function updateCheck($id,$params=[],$row=null){ + if($params && $row){ +// var_dump($this->no_auth_fields_check($params,$row)); + if(!$this->no_auth_fields_check($params,$row)){ + return true; + } + } + + // 课程存在售后订单则不允许操作 + $order = Order::where("classes_activity_item_id",$id)->where("status","not in","-3,6,9")->find(); + if($order)throw new \Exception("{$order['name']}存在正在使用中的订单报名学员,规格无法继续操作,如规格有误请下架!"); + } + + + protected function update_check(&$params,$row=null) + { + $params["classes_activity_id"] = $params["classes_activity_id"] ?? 0; + if($row){ + if(empty($params["shop_id"]))$params["shop_id"] = $row["shop_id"]; + $activity = \app\common\model\school\classes\activity\Activity::where("id",$row["classes_activity_id"])->find(); + if($activity && empty($params["classes_activity_id"])){ + $params["classes_activity_id"] = $activity["id"]; + } + } + + + //审核失败需填写原因 + if($params["auth_status"] == '2' && empty($params["reason"])){ + $this->error("审核失败需填写原因"); + } + + + // + + try { + $classesLib = new \app\common\model\school\classes\activity\ActivityAuth(); + $classesLib->no_auth_fields = $this->no_auth_fields; + $classesLib->need_auth = $this->need_auth; + $classesLib->have_auth = $this->have_auth; + + $classesLib->activityCheck($params,null,$row); + + $this->need_auth = $classesLib->need_auth; + $this->have_auth = $classesLib->have_auth; + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + + + + + + //修改 + if($row){ + +// if($params["auth_status"] != '1' && $row["auth_status"] == '1'){ +// $this->error("审核已通过的课程不允许再修改审核状态!"); +// } + + if($params["auth_status"] != '0' && $row["auth_status"] == '0'){ + //填写审核时间和审核人 + $params["auth_time"] = time(); + $params["admin_id"] = $this->auth->id; + if($params["auth_status"] == '1'){ + //审核通过 + $this->success_auth = true; + } + + if($params["auth_status"] == '2'){ + //审核通过 + $this->error_auth = true; + } + } + + + + }else{ + //新增 + //新增 + $params["add_type"] = '2'; + $params["add_id"] = $this->auth->id; + } + + } + + + /** + * 添加 + * + * @return string + * @throws \think\Exception + */ + public function add() + { + if (false === $this->request->isPost()) { + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + + $this->error(__('添加功能已被禁用!', '')); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + + $this->update_check($params,$row=null); + $spec = $params["item_json"]; + unset($params["item_json"]); + $result = $this->model->allowField(true)->save($params); + //添加课程规格 + foreach ($spec as $k=>$v){ + $v["classes_activity_auth_id"] = $this->model["id"]; + $v["classes_activity_id"] = $v["classes_activity_id"] ?? ($this->model->classes_activity_id ?? 0); + + $v["manystore_id"] = $this->model["manystore_id"]; + $v["shop_id"] = $this->model["shop_id"]; + + unset($v["id"]); + (new \app\common\model\school\classes\activity\ActivityItemAuth())->allowField(true)->save($v); + } + + //因为是批量添加,所有规格重新进行检测,防止出现时间重叠 + $specss = \app\common\model\school\classes\activity\ActivityItemAuth::where("classes_activity_auth_id",$this->model["id"])->select(); + foreach ($specss as $k=>$specs){ + $params =$specs; + (new \app\common\model\school\classes\activity\ActivityItemAuth)->specCheck($params,null,$specs); + } + + + $this->update_classes($this->model["classes_activity_id"] ?? 0,$this->model); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage().$e->getFile().$e->getLine()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + + /** + * 编辑 + * + * @param $ids + * @return string + * @throws DbException + * @throws \think\Exception + */ + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + if (false === $this->request->isPost()) { + + $spec = \app\common\model\school\classes\activity\ActivityItemAuth::where("classes_activity_auth_id",$row["id"])->field("id,classes_activity_id,name,price,age,sex,limit_num,status,weigh")->order('weigh desc,id desc')->select(); + + $row["item_json"] = json_encode($spec); + + $this->view->assign('row', $row); + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $this->update_check($params,$row); + $spec = $params["item_json"] ?? []; + +// var_dump($spec); + + $delete_spec_ids = $params["delete_spec_ids"] ?? []; + unset($params["item_json"]); + unset($params["delete_spec_ids"]); + + $result = $row->allowField(true)->save($params); + + //添加课程规格 + foreach ($spec as $k=>$v){ + $v["classes_activity_auth_id"] = $row["id"]; + $v["classes_activity_id"] = $v["classes_activity_id"] ?? ($row->classes_activity_id ?? 0); + + $v["manystore_id"] = $row["manystore_id"]; + $v["shop_id"] = $row["shop_id"]; + //有id更新,否则新增 + if(isset($v["id"]) && $v["id"]){ + \app\common\model\school\classes\activity\ActivityItemAuth::update((new \app\common\model\school\classes\activity\ActivityItemAuth)->checkAssemblyParameters($v)); + }else{ + + \app\common\model\school\classes\activity\ActivityItemAuth::create((new \app\common\model\school\classes\activity\ActivityItemAuth)->checkAssemblyParameters($v)); + } + + } + //删除规格 + foreach ($delete_spec_ids as $k=>$delete_spec){ + + + (new \app\common\model\school\classes\activity\ActivityItemAuth)->updateCheck($delete_spec["id"]); + + $delete_spec->delete(); + } + + //因为是批量添加,所有规格重新进行检测,防止出现时间重叠 + $specss = \app\common\model\school\classes\activity\ActivityItemAuth::where("classes_activity_auth_id",$row["id"])->select(); + foreach ($specss as $k=>$specs){ + + $params =$specs; + (new \app\common\model\school\classes\activity\ActivityItemAuth)->specCheck($params,null,$specs); + } + $this->update_classes($row["classes_activity_id"] ?? 0 ,$row); + if($this->success_auth){ + $activity = (new \app\common\model\school\classes\activity\Activity)->successAuth($row["id"]); + + $this->update_classes($activity["id"] ?? 0 ,$row); + //调用通过事件 + $data = ['activity' => $row]; + \think\Hook::listen('activity_auth_success_after', $data); + } + + + if($this->error_auth){ + (new \app\common\model\school\classes\activity\Activity)->errorAuth($row["id"]); + //调用通过事件 + $data = ['activity' => $row]; + \think\Hook::listen('activity_auth_fail_after', $data); + + } + + + + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); + } + + /** + * 删除 + * + * @param $ids + * @return void + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException + */ + public function del($ids = null) + { + if (false === $this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ?: $this->request->post("ids"); + if (empty($ids)) { + $this->error(__('Parameter %s can not be empty', 'ids')); + } + $pk = $this->model->getPk(); + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + $list = $this->model->where($pk, 'in', $ids)->select(); + foreach ($list as $item) { + $this->updateCheck($item->id); + } + + + $count = 0; + Db::startTrans(); + try { + foreach ($list as $item) { + //删除课程规格 + \app\common\model\school\classes\activity\ActivityItemAuth::where("classes_activity_auth_id",$item->id)->delete(); +// \app\common\model\school\classes\activity\ActivityItem::where("classes_activity_id",$item->classes_activity_id)->delete(); + $count += $item->delete(); + } + Db::commit(); + } catch (PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($count) { + $this->success(); + } + $this->error(__('No rows were deleted')); + } + + } diff --git a/application/admin/lang/zh-cn/school/classes/activity/activity.php b/application/admin/lang/zh-cn/school/classes/activity/activity.php index 5d051a1..59f3abe 100644 --- a/application/admin/lang/zh-cn/school/classes/activity/activity.php +++ b/application/admin/lang/zh-cn/school/classes/activity/activity.php @@ -68,4 +68,7 @@ return [ 'Limit_num' => '本项目限定人数', 'Age' => '年龄限制描述', 'Item_json' => '活动项目', + 'Has_expire' => '是否过期', + 'Has_expire 1' => '往期活动', + 'Has_expire 2' => '进行中活动', ]; diff --git a/application/admin/lang/zh-cn/school/classes/activity/activity_auth.php b/application/admin/lang/zh-cn/school/classes/activity/activity_auth.php index b5cafcc..b97a187 100644 --- a/application/admin/lang/zh-cn/school/classes/activity/activity_auth.php +++ b/application/admin/lang/zh-cn/school/classes/activity/activity_auth.php @@ -68,5 +68,15 @@ return [ 'Deletetime' => '删除时间', 'Manystore.nickname' => '昵称', 'Shop.name' => '店铺名称', - 'Shop.logo' => '品牌LOGO' + 'Shop.logo' => '品牌LOGO', + 'Sex' => '性别限制', + 'Sex 1' => '男', + 'Sex 2' => '女', + 'Sex 3' => '男女不限', + 'Limit_num' => '本项目限定人数', + 'Age' => '年龄限制描述', + 'Item_json' => '活动项目', + 'Has_expire' => '是否过期', + 'Has_expire 1' => '往期活动', + 'Has_expire 2' => '进行中活动', ]; diff --git a/application/admin/lang/zh-cn/school/message.php b/application/admin/lang/zh-cn/school/message.php index 556b1fd..2496760 100644 --- a/application/admin/lang/zh-cn/school/message.php +++ b/application/admin/lang/zh-cn/school/message.php @@ -45,5 +45,7 @@ return [ 'Admin.nickname' => '昵称', 'Admin.avatar' => '头像', 'User.nickname' => '昵称', - 'User.avatar' => '头像' + 'User.avatar' => '头像', + 'Status activity' => '课程活动消息', + 'Mini_type activity_apply' => '课程活动审核', ]; diff --git a/application/admin/model/school/Message.php b/application/admin/model/school/Message.php index 59af4dc..8276a75 100644 --- a/application/admin/model/school/Message.php +++ b/application/admin/model/school/Message.php @@ -77,12 +77,12 @@ class Message extends BaseModel public function getStatusList() { - return ['system' => __('Status system'), 'classes' => __('Status classes'), 'order' => __('Status order')]; + return ['system' => __('Status system'), 'classes' => __('Status classes'), 'order' => __('Status order'),'activity' => __('Status activity')]; } public function getMiniTypeList() { - return ['order_notice' => __('Mini_type order_notice'), 'classes_auth' => __('Mini_type classes_auth'), 'classes_apply' => __('Mini_type classes_apply'), 'shop_apply' => __('Mini_type shop_apply'), 'classes_order_notice' => __('Mini_type classes_order_notice'), 'user_auth' => __('Mini_type user_auth'), 'aftercare' => __('Mini_type aftercare'), 'other' => __('Mini_type other')]; + return ['order_notice' => __('Mini_type order_notice'), 'classes_auth' => __('Mini_type classes_auth'), 'classes_apply' => __('Mini_type classes_apply') ,'activity_apply' => __('Mini_type activity_apply'), 'shop_apply' => __('Mini_type shop_apply'), 'classes_order_notice' => __('Mini_type classes_order_notice'), 'user_auth' => __('Mini_type user_auth'), 'aftercare' => __('Mini_type aftercare'), 'other' => __('Mini_type other')]; } diff --git a/application/admin/model/school/classes/activity/Activity.php b/application/admin/model/school/classes/activity/Activity.php index 76eedab..2690f1c 100644 --- a/application/admin/model/school/classes/activity/Activity.php +++ b/application/admin/model/school/classes/activity/Activity.php @@ -38,9 +38,28 @@ class Activity extends Model 'new_text', 'selfhot_text', 'expirestatus_text', - 'add_type_text' + 'add_type_text', + 'has_expire', ]; - + + public function getHasExpireList() + { + return ['1' => __('Has_expire 1'), '2' => __('Has_expire 2')]; + } + + + public function getHasExpireAttr($value, $data) + { + $end_time = (isset($data['end_time']) ? $data['end_time'] : ''); + if(!$end_time) return '2'; + + if( $end_time < time()) { + return '1'; + }else{ + return '2'; + } + + } protected static function init() { diff --git a/application/admin/model/school/classes/activity/ActivityAuth.php b/application/admin/model/school/classes/activity/ActivityAuth.php index d0924bc..f6df995 100644 --- a/application/admin/model/school/classes/activity/ActivityAuth.php +++ b/application/admin/model/school/classes/activity/ActivityAuth.php @@ -40,8 +40,28 @@ class ActivityAuth extends Model 'auth_status_text', 'expirestatus_text', 'add_type_text', - 'auth_time_text' + 'auth_time_text', + 'has_expire', ]; + + public function getHasExpireList() + { + return ['1' => __('Has_expire 1'), '2' => __('Has_expire 2')]; + } + + + public function getHasExpireAttr($value, $data) + { + $end_time = (isset($data['end_time']) ? $data['end_time'] : ''); + if(!$end_time) return '2'; + + if( $end_time < time()) { + return '1'; + }else{ + return '2'; + } + + } protected static function init() diff --git a/application/admin/view/school/classes/activity/activity_auth/add.html b/application/admin/view/school/classes/activity/activity_auth/add.html index fa62135..ad29ee1 100644 --- a/application/admin/view/school/classes/activity/activity_auth/add.html +++ b/application/admin/view/school/classes/activity/activity_auth/add.html @@ -1,21 +1,18 @@
-
- -
- -
-
-
- -
- -
-
+
- + + + + + + (没找到机构则点击按钮创建机构后重新下拉框选机构) + {:__('Add')} + +
@@ -52,90 +49,149 @@
+ + + +
+ +
+ + + + + + + + + + + + + + + + +
活动项名限定人数年龄限制是否上架男女价格
追加
+ + + +
+
+ + + + + + +
- - {$vo} {/foreach} - + ( 如果选独立位置需填写具体位置信息! ) +
+
+ + + + +
+
+ +
+
+ +
+ + + +
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ + + +
- +
-
+
+ +
- +
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- +
+ + + +
@@ -160,14 +216,22 @@
+ + + + + + + +
- +
- {foreach name="statusList" item="vo"} - - {/foreach} + {foreach name="statusList" item="vo"} + + {/foreach}
@@ -181,10 +245,10 @@
- + @@ -193,10 +257,10 @@
- + @@ -205,10 +269,10 @@
- + @@ -217,87 +281,18 @@
- +
-
- -
- -
- {foreach name="authStatusList" item="vo"} - - {/foreach} -
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
- {foreach name="expirestatusList" item="vo"} - - {/foreach} -
-
-
-
- -
- - -
-
-
- -
- -
-
-
- -
- -
-