'功能设置', 'wxapptpl' => '微信小程序订阅消息', 'wechattpl' => '微信公众号模板消息', 'trade' => '交易设置', 'recharge' => '充值设置', 'delivery' => '配送设置', 'pact' => '预约设置', 'vip' => '会员卡设置', 'other' => '其它设置', 'sign' => '签到设置', 'center' => '用户中心设置', ]; /** * 获取器: 转义数组格式 */ public function getValuesAttr($value) { return json_decode($value, true); } /** * 修改器: 转义成json格式 */ public function setValuesAttr($value) { return json_encode($value); } /** * 获取指定项设置 */ public static function getItem(string $key, $applet_id = null) { $data = self::getAll($applet_id); return isset($data[$key]) ? $data[$key]['values'] : []; } /** * 获取设置项信息 */ public static function detail(string $key,$applet_id = null) { is_null($applet_id) && $applet_id = self::$applet_id; $filter = [];// 筛选条件 $filter['key'] = $key; $filter['applet_id'] = $applet_id; return self::withoutGlobalScope()->where($filter)->find(); } /** * 全局缓存: 系统设置 */ public static function getAll($applet_id = null) { $self = new static; is_null($applet_id) && $applet_id = $self::$applet_id; $filter = [];// 筛选条件 $filter['applet_id'] = $applet_id; if (!$data = Cache::get('food_setting_' . $applet_id)) { $data = array_column($self::withoutGlobalScope()->where($filter)->select()->toArray(), null, 'key'); Cache::set('food_setting_' . $applet_id, $data); } return array_merge_multiple($self->defaultData(), $data); } /** * 更新系统设置 */ public function edit(string $key, array $values, $applet_id = null) { is_null($applet_id) && $applet_id = self::$applet_id; //如果是设置微信小程序订阅消息 if($key == 'wxapptpl'){ if(!$values = $this->wxapptpl($values,$applet_id)){ return false; } } $model = self::detail($key,$applet_id) ?: $this; Cache::delete('food_setting_' . $applet_id);// 删除系统设置缓存 return $model->save([ 'key' => $key, 'describe' => $this->describe[$key], 'values' => $values, 'applet_id' => $applet_id, ]) !== false; } /** * 餐饮微信订阅消息设置 */ private function wxapptpl(array $values,$applet_id) { //验证是否添加小程序餐饮服务目录 $wx = new Wechat; //获取已设置的服务类目 $result = $wx->getCategory($applet_id); $isSet = false;//是否符合设置要求 if($result['errcode']==0){ foreach ($result['categories'] as $item){ if($item['first']==402 AND $item['second']==1273 AND $item['audit_status']==3){ $isSet = true; break; } } if(!$isSet){ $this->error = '为该小程序添加“商业服务-软件/建站/技术开发”服务类目,并通过审核'; return false; } }else{ $this->error = $result['errmsg']; return false; } //获取帐号下的模板列表 if(!$result = $wx->getMessageTemplateList($applet_id)){ $this->error = $wx->getError(); return false; } //循环删除订阅消息模板 foreach ($result['data'] as $item){ if(!$wx->deleteMessageTemplate($applet_id,$item['priTmplId'])){ $this->error = $wx->getError(); return false; } } //添加商家接单通知 $tid = '31781'; //1商家名称,2订单状态,3接单时间 $kidlist = [1,2,3]; $desc ='商家接单通知'; if(!$result = $wx->addMessageTemplate($applet_id,$tid,$kidlist,$desc)){ $this->error = $wx->getError(); return false; } $values['receive'] = $result['priTmplId']; //添加骑手取货通知 $tid = '31780'; //1商家名称、2订单状态、3接单时间 $kidlist = [1,2,3]; $desc ='骑手接单通知'; if(!$result = $wx->addMessageTemplate($applet_id,$tid,$kidlist,$desc)){ $this->error = $wx->getError(); return false; } $values['horseman'] = $result['priTmplId']; //订单配送通知 $tid = '31339'; //8商家名称 9订单状态 5配送人、6配送电话 10送出时间 $kidlist = [8,9,5,6,10]; $desc ='订单配送通知'; if(!$result = $wx->addMessageTemplate($applet_id,$tid,$kidlist,$desc)){ $this->error = $wx->getError(); return false; } $values['delivery'] = $result['priTmplId']; //提货通知 $tid = '30804'; //3提货门店、2状态、6提货码、9提货地点、7联系电话 $kidlist = [3,2,6,9,7]; $desc ='提货通知'; if(!$result = $wx->addMessageTemplate($applet_id,$tid,$kidlist,$desc)){ $this->error = $wx->getError(); return false; } $values['take'] = $result['priTmplId']; //退款状态通知 $tid = '31441'; //8订单编号、9退款金额、4退款状态、5备注、 $kidlist = [8,9,4,5]; $desc ='退款状态通知'; if(!$result = $wx->addMessageTemplate($applet_id,$tid,$kidlist,$desc)){ $this->error = $wx->getError(); return false; } $values['refund'] = $result['priTmplId']; return $values; } /** * 默认配置 */ public function defaultData() { return [ 'pact' => [ 'key' => 'pacttable', 'describe' => '预约设置', 'values' => [ 'is_open' => 0, 'is_print' => 0, 'range' => 50, ], ], 'vip' => [ 'key' => 'vip', 'describe' => '会员卡设置', 'values' => [ 'is_open' => 1,//是否开启 'buy_price' => '10',//购买价格 'vip_discount' => 1,//1开启 0关闭 'vip' => [ 0 => [ 'card_cover' => base_url() . 'addons/food/img/v1.png', 'name' => 'V1', 'discount' => 100,//等级折扣 'score' => 0, 'free_delivery' => 0,//是否免配送费 'gift' => [] ], 1 => [ 'card_cover' => base_url() . 'addons/food/img/v2.png', 'name' => 'V2', 'discount' => 95,//等级折扣 'score' => 500, 'free_delivery' => 0,//是否免配送费 'gift' => [] ], 2 => [ 'card_cover' => base_url() . 'addons/food/img/v3.png', 'name' => 'V3', 'discount' => 90,//等级折扣 'score' => 1000, 'free_delivery' => 0,//是否免配送费 'gift' => [] ], 3 => [ 'card_cover' => base_url() . 'addons/food/img/v4.png', 'name' => 'V4', 'discount' => 85,//等级折扣 'score' => 2000, 'free_delivery' => 0,//是否免配送费 'gift' => [] ], 4 => [ 'card_cover' => base_url() . 'addons/food/img/v5.png', 'name' => 'V5', 'discount' => 80,//等级折扣 'score' => 5000, 'free_delivery' => 0,//是否免配送费 'gift' => [] ], 5 => [ 'card_cover' => base_url() . 'addons/food/img/v6.png', 'name' => 'V6', 'discount' => 75,//等级折扣 'score' => 10000,//所需积分 'free_delivery' => 0,//是否免配送费 'gift' => [] ], ] ], ], 'sign' => [ 'key' => 'sign', 'describe' => '签到设置', 'values' => [ 'type' => 'score',//奖励类型 score=积分,money=余额 'mode' => 'fixed',//奖励模式 fixed=固定,random=随机 'number' => 1,// 'plan' => [ /*0 => [ 'days' => 15,//连续天数 'number' => 10,//额外奖励 'type' => 'score',//奖励类型 ],*/ ], 'describe' => '1. 每次签到赠送1积分 2. 连续签到15天,额外赠送10积分 3. 连续签到30天,额外赠送40积分', //签到说明 ], ], 'trade' => [ 'key' => 'trade', 'describe' => '交易设置', 'values' => [ 'order' => [ 'time' => '10',//任务执行间隔 'close_time' => '30',//未支付订单关闭时间 'delivery_time' => '30',//已配送订单自动配送完成时间 'receive_time' => '30', //配送完毕订单用户自动确认收货时间 'cmt_time' => '120', //收货订单用户自动评价时间 'refund_time' => '0', //退款订单自动退款时间 'manzu_n_money' => 15, // 满足n元赠送优惠券 ], 'freight_rule' => '10', ] ], 'delivery' => [ 'key' => 'delivery', 'describe' => '配送设置', 'values' => [ 'delivery_range' => '3000', //配送范围 'free_range' => '0', //免费配送范围 'delivery_price' => '5', //配送费用 'min_price' => '15', //起送价格 ] ], 'other' => [ 'key' => 'other', 'describe' => '其它设置', 'values' => [ 'bind_phone' => 1,//登录小程序是否强制用户绑定手机号 'is_stock' => 0,//是否启用商品库存 'order_export' => 'col', //订单导出样式 col竖排,row横排 'postpaid' => [ '10' => 0, '20' => 0, '30' => 0, ],//后付费设置 'open_shop' => 1,//首次打开小程序点单页,是否弹出门店列表 'is_calling' => 1,//是否开启叫号服务,需对接叫号器,堂食扫码有效 'balance_pay' => 0,//余额买单 'goods' => [ 'sell_out' => 1,//售罄显示 'delisting' => 0,//下架显示 ],//商品设置 ] ], 'wxapptpl' => [ 'key' => 'wxapptpl', 'describe' => '微信小程序订阅消息', 'values' => [ 'receive' => '',//商家接单通知 'horseman' => '',//骑手取货通知 'delivery' => '', //订单配送通知 'take' => '', //取餐提醒 'refund' => '', //退款状态通知 ], ], 'wechattpl' => [ 'key' => 'wechattpl', 'describe' => '微信公众号模板消息', 'values' => [ 'receive' => '',//商家接单通知 'horseman' => '',//骑手取货通知 'delivery' => '', //订单配送通知 'take' => '', //取餐提醒 'finish' => '', //订单完成通知 'refund' => '', //退款状态通知 ], ], 'recharge' => [ 'key' => 'recharge', 'describe' => '充值设置', 'values' => [ 'is_open' => 1, //是否开启 'is_custom' => 1, //是否允许用户自定义金额 'describe' => '1. 账户充值仅限微信在线支付方式,充值金额实时到账 2. 账户充值套餐赠送的金额即时到账 3. 账户余额有效期:自充值日起至用完即止 4. 储值金额不可提现、不计利息、不可转赠', //充值说明 ], ], 'center' => [ 'key' => 'center', 'describe' => '用户中心设置', 'values' => [ 'vip' => 1, //会员卡 'setting' => 1, //权限设置 'helper' => 1, //商家助手 'contact' => [//联系我们 'is_open' => 1, 'type' => 'wechat',//wechat=微信客服 phone=联系电话 'phone' => '',//电话号码 ], 'menu' => [ 0 => [ 'logo' => base_url() . 'addons/food/img/applet/pact.png', 'title' => '预约订桌', 'path' => 'user/pact/index', 'sort' => 10 ], 1 => [ 'logo' => base_url() . 'addons/food/img/applet/coupon.png', 'title' => '我的卡券', 'path' => 'user/coupon/index', 'sort' => 20 ], 2 => [ 'logo' => base_url() . 'addons/food/img/applet/address.png', 'title' => '我的地址', 'path' => 'user/address/index', 'sort' => 30 ], 3 => [ 'logo' => base_url() . 'addons/food/img/applet/collection.png', 'title' => '签到中心', 'path' => 'user/sign/index', 'sort' => 40 ], 4 => [ 'logo' => base_url() . 'addons/food/img/applet/comment.png', 'title' => '评价记录', 'path' => 'user/comment/index', 'sort' => 50 ], ], ], ], ]; } }