id = post_params("id", 0) ?: get_params("id", 0); //如果是get就获取数据 if (\Yii::$app->request->isGet) { $res = $form->merchantInfo(); } else { $form->merchant_info = post_params("merchant_info"); $res = $form->save(); } return $this->asJson($res); } /** * 商户进件结果查询 * @return \yii\web\Response */ public function actionMerchantStatus() { $Merchant = new \app\utils\yunst\src\Merchant(); $res = $Merchant->queryMerchantStatus(get_store_id()); } /** * 商户进件信息查询 * @return \yii\web\Response */ public function actionMerchantInfo() { $Merchant = new \app\utils\yunst\src\Merchant(); $res = $Merchant->queryMerchantInfo(get_store_id()); } /** * 是否可以协议签约 */ public function actionIsSignProtocol() { $merchant_info = MerchantInfo::findOne(['store_id' => get_store_id(), 'status'=> 3, 'is_yunst' => 1, 'is_delete' => 0]); if ($merchant_info){ $store = Store::findOne(['id' => get_store_id()]); return $this->asJson(['code'=>0,'msg'=>'协议可签约','data'=>['ratio'=>$store->ratio??0]]); }else{ return $this->asJson(['code'=>1,'msg'=>'商户进件信息不存在']); } } /** * 商户协议签约URL * @return \yii\web\Response */ public function actionSignProtocol() { $Merchant = new \app\utils\yunst\src\Merchant(); $store = Store::findOne(['id' => get_store_id()]); $ratio = post_params("ratio", 0); if (!$ratio){ return $this->asJson(['code'=>1,'msg'=>'抽成比例不能为空']); } if (floatval($store->ratio) > 0) { return $this->asJson(['code'=>1,'msg'=>'已经签约过 不可重复操作']); } $store->ratio = $ratio; $store->save(); //查询商户进件信息 $merchant_info = MerchantInfo::findOne(['store_id' => get_store_id(),'status'=> 3, 'is_yunst' => 1, 'is_delete' => 0]); if (!$merchant_info){ return $this->asJson(['code'=>1,'msg'=>'商户进件信息不存在']); } $authorizedCustName = json_decode($merchant_info->business_info,true)['merchant_shortname']; $authorizedCustId = $merchant_info->sub_mch_id; $data['bizUserId'] = $store->store_number; $data['cusid'] = $authorizedCustId; $data['commMode'] = 'rate'; $data['commRatio'] = $ratio; $data['commAmoun'] = ''; $data['authWay']= 'smscode'; $data['authorizedCustName']= $authorizedCustName;//被授权的客户名称 ISV 入驻通联时提交的营业执照名称 // $data['authorizedCustName']= "大同三然珠宝有限公司"; //被授权的客户名称 ISV 入驻通联时提交的营业执照名称 // $data['authorizedCustId']= '082207111000028'; $data['protocolType']= '2'; $data['notifyUrl']= \Yii::$app->request->hostInfo; $data['jumpUrl']= \Yii::$app->request->hostInfo; $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value']; if ($oldConf){ $oldConf = json_decode($oldConf, true); // $data['authorizedCustName']= '贵州名宾连锁科技有限公司'; $data['authorizedCustId']= $oldConf['customer_number']; } // print_r($data);die(); $res = $Merchant->signProtocol(get_store_id(),$data); // return $this->asJson(['code'=>1,'msg'=>$data]); // return $this->asJson(['code'=>1,'msg'=>$res]); if ($res['code'] == 10000 && $res['subCode']=='SUCCESS'){ return $this->asJson(['code'=>0,'data'=>$res['data'],'msg'=>$res['subMsg'],'signProtocolUrl'=>$res['data']['signProtocolUrl']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } // print_r($res);die; } /** * 商户协议签约状态查询 * @return \yii\web\Response */ public function actionSignProtocolStatus() { $Merchant = new \app\utils\yunst\src\Merchant(); $store = Store::findOne(['id' => get_store_id()]); // if (!$store->cusid){ // return [ // 'code' => 1, // 'msg' => '进件商户号不存在' // ]; // } $data['cusid'] = $store->cusid; $data['protocolType']= '2'; //print_r($data);die(); $res = $Merchant->protocolStaus(get_store_id(),$data); // return $this->asJson(['code'=>0,'msg'=>$res['subMsg']]); if ($res['subCode']!='FAIL'){ return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } public function actionPay() { $orderYunst = new \app\utils\yunst\src\OrderYunst(); $store = Store::findOne(['id' => get_store_id()]); $res = $orderYunst->payYunst(); return $this->asJson(['code'=>0,'msg'=>$res]); if ($res['subCode']!='FAIL'){ return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } /** * 聚合收款交易对账文件(收银宝接口) * @return \yii\web\Response */ public function actionGetFile() { if (empty(SaasForm::yunstSetting(1))) { return $this->asJson(['code' => 1, 'msg' => '通联服务商参数配置不完善']); } $orderYunst = new \app\utils\yunst\src\OrderYunst(); $store = Store::findOne(['id' => get_store_id()]); if (empty($store->cusid)) { return $this->asJson(['code' => 1, 'msg' => '通联参数配置不完善']); } $date = post_params('date',''); $res = $orderYunst->getTrxFile($date,$store->cusid); if ($res['subCode']!='FAIL'){ return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } /** *商户结算资金管理类交易对账文件 * @return \yii\web\Response */ public function actionGetAccountFile() { if (empty(SaasForm::yunstSetting(1))) { return $this->asJson(['code' => 1, 'msg' => '通联服务商参数配置不完善']); } $orderYunst = new \app\utils\yunst\src\OrderYunst(); $date = post_params('date',''); $res = $orderYunst->getCheckAccountFile($date); // print_r($res);die; if ($res['subCode']!='FAIL'){ $file_url = $res['data']['detailUrl']; // 获取文件内容并转码 $dataString = file_get_contents($file_url); $dataString = mb_convert_encoding($dataString, 'UTF-8', 'GBK'); // $dataString = "CY0b6eb06781205e81706235034|202401261862102508906876928|服务商抽佣|100|10||20240126101035|| // CY413362f65eb60431706238185|202401261862115728317091840|服务商抽佣|10|1||20240126110307|| // AL20240125172538203993|202401261862163495248859136|服务商抽佣|20000|2000||20240126141256|| // AL20240126142846101335|202401261862169223070093312|服务商抽佣|10000|1000||20240126143542|| // AL20240126151652308322|202401261862179960379281408|服务商抽佣|10000|1000||20240126151821|| // AL20240126160130287708|202401261862191204138094592|服务商抽佣|10000|1000||20240126160302|| // SC20240126161814865844|202401261862195170238402560|服务商抽佣|12000|1200||20240126161847||"; // 使用 explode() 函数将字符串拆分成数组 $dataArray = explode('|', $dataString); // 删除数组中的最后一个元素 array_pop($dataArray); // 移除数组中的空元素 // $dataArray = array_filter($dataArray); // 将一维数组转换为二维数组,每个子数组包含8个元素 $resultArray = []; $chunkedArray = array_chunk($dataArray, 8); // print_r($chunkedArray);die; // 输出结果 // print_r($chunkedArray);die; if ($chunkedArray){ foreach ($chunkedArray as $item) { $resultArray[] = [ 'order_no' => trim($item[0]),//商户订单号 'order_time' => $item[1],//云商通联商户订单号 'order_type' => $item[2],//订单类型 'order_amount' => $item[3],//订单金额 'order_fee' => $item[4],//抽用金额 'order_status' => $item[5],//手续费 'order_remark' => $item[6],//交易完成时间 'order_time_str' => $item[7],//原商户订单号 ]; } foreach ($resultArray as $key=>$item){ $resultArray[$key]['mch_name'] = ''; //处理数据结构 //查询商户信息 $orderNoHead = substr($item['order_no'], 0, 2); if ($orderNoHead == 'SC'){ $order_info = Order::find()->where(['order_no' => $item['order_no']])->one(); if ($order_info){ $store_info = Store::find()->where(['store_id' => $order_info->store_id])->one(); if ($store_info){ $resultArray[$key]['mch_name'] = $store_info->name; }else{ $resultArray[$key]['mch_name'] = '平台'; } }else{ $resultArray[$key]['mch_name'] = ''; } } if ($orderNoHead == 'AL'){ $order_info = \app\models\Order::find()->where(['order_no' => $item['order_no']])->one(); if ($order_info){ $store_info = Store::find()->where(['store_id' => $order_info->store_id])->one(); if ($store_info){ $resultArray[$key]['mch_name'] = $store_info->name; }else{ $resultArray[$key]['mch_name'] = '平台'; } }else{ $resultArray[$key]['mch_name'] = ''; } } } return $this->asJson(['code'=>0,'data'=>$resultArray??'']); }else{ return $this->asJson(['code'=>1,'msg'=>'暂无对账数据']); } return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } /** * 订单查询 本接口支持查询“服务商抽佣、服务商抽佣退款、商户资金结算/服务商提现”的订单的订单状态 * @return \yii\web\Response */ public function actionOrderCheck() { $orderYunst = new \app\utils\yunst\src\OrderYunst(); $store = Store::findOne(['id' => get_store_id()]); $data['bizOrderNo'] = 'SC20240123145958400674'; $data['orderNo'] ='202401241861428958520807424'; $res = $orderYunst->getOrderStatus($data); return $this->asJson(['code'=>0,'msg'=>$res]); if ($res['subCode']!='FAIL'){ return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } public function actionOrder() { $orderYunst = new \app\utils\yunst\src\OrderYunst(); $store = Store::findOne(['id' => get_store_id()]); $data['bizOrderNo'] = 'SC20240123145958400674'; $data['orderNo'] ='202401241861428958520807424'; $res = $orderYunst->getOrderStatus($data); return $this->asJson(['code'=>0,'msg'=>$res]); if ($res['subCode']!='FAIL'){ return $this->asJson(['code'=>0,'data'=>$res['data']??'','msg'=>$res['subMsg']]); }else{ return $this->asJson(['code'=>1,'msg'=>$res['subMsg']]); } } public function actionList() { $form = new WechatMiniMerchantForm(); $form->status = get_params("status",-1); $res = $form->list2(); return $this->asJson($res); } public function actionGetCountry() { $form = new WechatMiniMerchantForm(); $res = $form->getCountry(); return $this->asJson($res); } // 获取小程序开始使用/暂停使用 public function actionMiniIsUse(){ $form = new WechatMiniMerchantForm(); $form->id = post_params("id")??get_params("id"); $form->is_use = post_params("is_use"); $res = $form->unbind(); return $this->asJson($res); } //设置店铺会员号 public function actionSetStoreNumber() { try { $store_number = trim(post_params('store_number')); $store_id = get_store_id(); $store = Store::findOne($store_id); if (!$store) { throw new \Exception('店铺信息不存在'); } if (\Yii::$app->request->isPost) { if (!empty(trim($store->yunst_user_id))) { throw new \Exception('已经设置并提交成功 不可重复操作!'); } if (!$store_number) { throw new \Exception('请输入商城会员编号!'); } $store_info = Store::find()->where(['is_delete' => 0, 'store_number' => $store_number])->one(); if ($store_info){ throw new \Exception('会员编号已存在'); } //判断后台开启通联 $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value']; if ($oldConf) { $oldConf = json_decode($oldConf, true); if (empty($oldConf) || empty(trim($oldConf['appid']))) { throw new \Exception('平台配置信息缺失 需完善后重试'); } //调用第三方会员创建接口 $memberService = new MemberService(); $res_member = $memberService->createMember($store_number,2); if ($res_member['subCode'] == "FAIL"){ throw new \Exception($res_member['subMsg']); } $store->yunst_user_id = $res_member['data']['userId'] ?? ''; } $store->store_number = $store_number; if (!$store->save()) { throw new \Exception(json_encode($store->errors, JSON_UNESCAPED_UNICODE)); } return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } else { $data = [ 'store_number' => $store->store_number ?? '' ]; return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $data ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } }