0) { return $data['parent_id']; } return $data['user_id']; } public function getShopId() { return request()->header("shop",0); } public function getAccountId(array $data) { return $data['account_id']; } protected function getDyConfig(): array { return ["appid" => sConf('dy.appid'),'secret' => sConf('dy.secret')]; } /** * 同步订单-实时 * @param string $account * @param string $openId */ protected function asyncDyOrder(string $account = "",string $openId = "",string $orderId = "") { // 同步已经下单的订单 if (!empty($account)) { if (!empty($orderId)) { $order = (new SaasOrderLife)->where("order_id",$orderId)->findOrEmpty(); if (!$order->isEmpty()) return []; } $resp = (new Client)->config($this->getDyConfig())->token()->queryOrder($account,$openId); $store = (new SaasStore)->where("store_id",$account)->findOrEmpty(); if (empty($resp['data']['orders'])) return []; $lifeOrder = $resp['data']['orders'][0]; $orderData = $orderLog = []; foreach ($lifeOrder['certificates'] as $key=>$val) { $orderEx = (new SaasOrderLife)->where("order_id",$lifeOrder['order_id'])->where("certificate_id",$val['certificate_id'])->findOrEmpty(); if ($orderEx->isEmpty()) { $orderData[$key] = [ "open_id" => $openId, "agent_id" => $store['agent_id']??'', "store_id" => $store['store_id']??'', "order_id" => $lifeOrder['order_id'], "pay_amount" => $val['amount']['pay_amount'], "order_amount" => $val['amount']['original_amount'], "expire_at" => date("Y-m-d H:i:s",$val['expire_time']), "out_id" => $val['sku_info']['sku_id'], "product_name" => $val['sku_info']['title'], "groupon_type" => $val['sku_info']['groupon_type'], "certificate_id" => $val['certificate_id']??'', "status" => 1, "pay_at" => getDateFull(), "start_time" => date("Y-m-d H:i:s",$val['start_time']), ]; } else { $orderEx->save([ "open_id" => $openId, "expire_at" => date("Y-m-d H:i:s",$val['expire_time']), "out_id" => $val['sku_info']['sku_id'], "product_name" => $val['sku_info']['title'], "groupon_type" => $val['sku_info']['groupon_type'], "certificate_id" => $val['certificate_id']??'', "start_time" => date("Y-m-d H:i:s",$val['start_time']), ]); } } if (!empty($orderData)) { (new SaasOrderLife)->insertAll(array_values($orderData)); } return []; } } /** * 写入新用户 * @param array $param * @return bool */ protected function sceneUser(array $param = [],int $type = 1,$field = "agent_id"): bool { if (!isset($param['id'])) { $param['salt'] = strtoupper(CodeExtend::random(10,3)); $param['password'] = md5($param['password'].$param['salt']); $param['create_ip'] = request()->getRealIp() ?: '127.0.0.1'; $param['type'] = $type; } return (new SystemUser)->setAutoData($param,$field); } protected function getSmsChannel(): array { return [ [ "name" => "阿里云", "type" => "aliyun", "url" => "https://dysms.console.aliyun.com/dysms.htm" ], [ "name" => "腾讯云", "type" => "qcloud", "url" => "https://console.cloud.tencent.com/smsv2" ], [ "name" => "七牛云", "type" => "qiniu", "url" => "https://portal.qiniu.com/sms/dashboard" ] ]; } /** * 快捷输入并验证( 支持 规则 # 别名 ) * @param array $rules 验证规则( 验证信息数组 ) * @param array|string $input 输入方式 ( post. 或 get. ) * @param callable|null $callable 异常处理操作 */ protected function _valid(array $rules, array|string $input = '', ?callable $callable = null) { if (is_string($input)) { $type = trim($input, '.') ?: 'get'; $input = request()->$type(); } [$data, $rule, $info] = [[], [], []]; foreach ($rules as $name => $message) if (is_numeric($name)) { [$name, $alias] = explode('#', $message . '#'); $data[$name] = $input[($alias ?: $name)] ?? null; } elseif (!str_contains($name, '.')) { $data[$name] = $message; } elseif (preg_match('|^(.*?)\.(.*?)#(.*?)#?$|', $name . '#', $matches)) { [, $_key, $_rule, $alias] = $matches; if (in_array($_rule, ['value', 'default'])) { if ($_rule === 'value') $data[$_key] = $message; elseif ($_rule === 'default') $data[$_key] = $input[($alias ?: $_key)] ?? $message; } else { $info[explode(':', $name)[0]] = $message; $data[$_key] = $data[$_key] ?? ($input[($alias ?: $_key)] ?? null); $rule[$_key] = isset($rule[$_key]) ? ($rule[$_key] . '|' . $_rule) : $_rule; } } $validate = new Validate(); if ($validate->rule($rule)->message($info)->check($data)) { return $data; } elseif (is_callable($callable)) { return call_user_func($callable, $validate->getError(), $data); } else { return $validate->getError(); } } /** * 菜单信息格式化 * @param array $menus * @param int $type * @param int $mch * @return array */ protected function filterMenu(array $menus,int $type,int $mch = 0): array { foreach ($menus as &$menu) { $menu['meta'] = [ "title" => $menu['title'], "icon" => $menu['icon']??'', "type" => $menu['type'] ]; if (!empty($menu['children'])) { $menu['children'] = $this->filterMenu($menu['children'],$type,$mch); } if ($mch > 0) { $menu['component'] = ($mch==1?'merchant/':'store/').$menu['name']; } else { $menu['component'] = $menu['name']; } $menu['isMenu'] = $menu['status']; if($type == 1) unset($menu['title'],$menu['icon'],$menu['type'],$menu['pid'],$menu['id']); } return $menus; } }