| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\common\controllers;
- use app\constants\OptionSetting;
- use app\events\OrderEvent;
- use app\events\SupplierOrderEvent;
- use app\jobs\SharingReceiverHandleJob;
- use app\jobs\SyncSharerListJob;
- use app\jobs\YunstAutoCashJob;
- use app\models\AccountLog;
- use app\models\Cash;
- use app\models\Goods;
- use app\models\GoodsBook;
- use app\models\Level;
- use app\models\Lg;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderRefund;
- use app\models\SaasUser;
- use app\models\SaasUserPriceLog;
- use app\models\SharingReceiver;
- use app\models\Shop;
- use app\models\ShopShare;
- use app\models\Store;
- use app\models\StoreCash;
- use app\models\Supplier;
- use app\models\User;
- use app\utils\LgApi;
- use app\utils\OrderNo;
- use app\utils\yunst\src\OrderYunst;
- use yii\helpers\Json;
- use yii\web\Controller;
- use app\modules\admin\models\pospal\PospalForm;
- class TaskController extends Controller
- {
- public function actionTest() {
- $order = Order::findOne(8659);
- \app\utils\Share\BonusPool::generalUserConsume($order['user_id'], $order['store_id']);
- }
- /**
- * 订单,售后,发放积分,分销处理入口
- */
- public function actionExecute() {
- $h = date('H');
- $i = date('i');
- $s = date('s');
- $is = cache()->get('task_lock');
- if ($is) {
- return;
- }
- cache()->set('task_lock', 1, 50);
- // 商城列表
- $store_list = Store::find()->where(['is_delete' => 0])->select('id, name')->all();
- // 订单处理
- // $queue = queue_push(new \app\jobs\OrderEventJob([
- // 'in_action' => 'executeOrder',
- // ]));
- if(date('i') % 10 == 2){
- $queue = queue_push(new \app\jobs\orderEvent\StoreWxOrderShippingJob());
- }
- $supplier_list = Supplier::find()->where(['and',['is_delete' => 0], ['>', 'cloud_supplier_id', 0]])->all();
- foreach($supplier_list as $supplier) {
- try {
- // 定时任务
- $event = new SupplierOrderEvent();
- $event->supplier_id = $supplier->cloud_supplier_id;
- $event->onLoad();
- } catch(\Exception $e) {
- \Yii::error('--------auto-execute-error---- '.$supplier->id.' ----auto-execute-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
- // 同步视频号小店
- if(date('i') % 10 == 0){
- $SyncSharerStoreId = null;
- if (\Yii::$app->prod_is_duli()) {
- $SyncSharerStoreId = 1;
- }
- $queue = queue_push(new SyncSharerListJob(['type' => 1, 'store_id' => $SyncSharerStoreId]));
- $queue = queue_push(new SyncSharerListJob(['type' => 2, 'store_id' => $SyncSharerStoreId]));
- $queue = queue_push(new SyncSharerListJob(['type' => 3, 'store_id' => $SyncSharerStoreId]));
- $queue = queue_push(new SharingReceiverHandleJob());
- }
- // $queue = queue_push(new \app\jobs\OrderEventJob([
- // 'in_action' => 'executeLevel',
- // ]));
- $queue = queue_push(new \app\jobs\orderEvent\OtherThirdJob());
- // $queue = queue_push(new \app\jobs\OrderEventJob([
- // 'in_action' => 'executeAdapayShareToSelf',
- // ]));
- // $version = time();
- // cache()->set('executeBonusPool', $version);
- // $queue = queue_push(new \app\jobs\OrderEventJob([
- // 'in_action' => 'executeBonusPool',
- // 'version' => $version,
- // ]));
- if(date('Hi') === '0101'){
- $queue = queue_push(new \app\jobs\orderEvent\JuShuiTanTokenJob());
- /**
- * 全域分佣奖金池自动发放
- */
- $queue = queue_push(new \app\jobs\orderEvent\ReportPoolJob());
- }
- $queue = queue_push(new \app\jobs\orderEvent\Order2JstSupplierJob());
- if(date('Hi') === '0111'){
- $queue = queue_push(new \app\jobs\orderEvent\JuShuiTanTokenSupplierJob());
- }
- if(date('Hi') === '0121'){
- $queue = queue_push(new \app\jobs\orderEvent\MaiyatianTokenJob());
- }
- if(date('Hi') === '0201'){
- $res = \app\modules\admin\models\ActivityOrderRebateSelfForm::rebate(0, 1);
- }
- if(date('His') == '000000'){
- $queue = queue_push(new \app\jobs\orderEvent\WechatCashStatusJob());
- //定时任务 查询用户等级到期时间
- $queue = queue_push(new \app\jobs\orderEvent\UserLevelExpiresHandleJob());
- }
- $queue = queue_push(new \app\jobs\orderEvent\AutoSendTeamGradesPoolJob());
- if($h.$i.$s == '000100'){
- queue_push(new \app\jobs\ConsumptionGrowthValueJob());
- }
- //固定时间重置分拣顺序
- queue_push(new \app\jobs\CentralizeGoodsExtSortKeyJob());
- return $this->asJson([
- 'code' => 0,
- 'msg' => '执行完毕'
- ]);
- }
- /**
- * 从银豹同步订单到赤店
- */
- public function actionYinbaoSyncOrders() {
- // 商城列表
- $store_list = Store::find()->where(['is_delete' => 0])->all();
- foreach($store_list as $store) {
- try {
- // 定时任务
- (new PospalForm(['store_id' => $store->id]))->syncOrders();
- } catch(\Exception $e) {
- \Yii::error('--------auto-execute-error---- '.$store->id.' ----auto-execute-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '执行完毕'
- ]);
- }
- /**
- * 自动下架预约时间到期商品
- * 脚本执行时间:00:00
- */
- public function actionAutoOffGoods() {
- return $this->asJson([]);
- $goods_book = Goods::find()->alias('g')->leftJoin(['gb' => GoodsBook::tableName()], 'g.id=gb.goods_id')
- ->where(['g.is_delete' => 0, 'g.status' => 1])
- ->andWhere(['in', 'g.product_type', [1, 2]])->select('g.product_type, g.id, gb.date_book, gb.service_book')->asArray()->all();
- if (empty($goods_book)) {
- return $this->asJson([]);
- }
- $book_goods_ids = [];
- $today = strtotime(date('Y-m-d'));
- foreach ($goods_book as $book) {
- // 酒店预约商品
- if ($book['product_type'] == Goods::GOODS_TYPE_DATE) {
- $date_book = Json::decode($book['date_book']);
- $book_date_arr = array_column($date_book, 'date');
- if (empty($book_date_arr)) {
- $book_goods_ids[] = $book['id'];
- continue;
- }
- $count = 0;
- foreach ($book_date_arr as $value) {
- if (strtotime($value) >= $today) {
- $count ++;
- }
- }
- if ($count < 1) {
- $book_goods_ids[] = $book['id'];
- }
- }
- // 服务预约商品
- if ($book['product_type'] == Goods::GOODS_TYPE_TIME) {
- $service_book = Json::decode($book['service_book']);
- $service_date_arr = array_column($service_book['data'], 'date');
- if (empty($service_date_arr)) {
- $book_goods_ids[] = $book['id'];
- continue;
- }
- $count = 0;
- foreach ($service_date_arr as $value) {
- if (strtotime($value) >= $today) {
- $count ++;
- }
- }
- if ($count < 1) {
- $book_goods_ids[] = $book['id'];
- }
- }
- }
- // 下架商品
- if (!empty($book_goods_ids)) {
- Goods::updateAll(['status' => Goods::STATUS_DISABLE], ['in', 'id', $book_goods_ids]);
- \Yii::warning([date('Y-m-d') . ' 自动下架预约过期商品,ID为:', $book_goods_ids]);
- }
- }
- /**
- * 处理通联分账失败
- */
- public function actionYunstFail(){
- $store_list = Store::find()->where(['is_delete' => 0])->select('id, name')->all();
- foreach($store_list as $store) {
- try {
- /**
- * 查询待分账的记录
- */
- $receivers_share = SharingReceiver::find()->where(['store_id' => $store->id
- ])
- ->andWhere(['is_pay'=>SharingReceiver::PAY_FAIL])
- ->asArray()
- ->all();
- debug_log('开始分账');
- debug_log($receivers_share);
- foreach($receivers_share as $receivers_share1){
- sleep(1);
- //开始分账
- debug_log('开始分账1');
- debug_log($receivers_share1);
- $orderNoHead = substr($receivers_share1['order_no'], 0, 2);
- $where = [];
- $is_mall = 0;
- $is_scan = 0;
- $model = Order::find();
- switch ($orderNoHead) {
- case 'ML':
- $is_mall = 1;
- //商盟会员购物订单
- $model = Order::find();
- $where = [
- 'order_no' => $receivers_share1['order_no'],
- 'is_delete' => 0,
- 'trade_status' => Order::ORDER_FLOW_CONFIRM
- ];
- break;
- case 'AL':
- //商盟会员购物订单
- $model = Order::find();
- $where = [
- 'order_no' => $receivers_share1['order_no'],
- 'is_delete' => 0,
- 'trade_status' => Order::ORDER_FLOW_CONFIRM
- ];
- break;
- case 'SC':
- //当面付订单
- $model = \app\plugins\scanCodePay\models\Order::find();
- $where = [
- 'order_no' => $receivers_share1['order_no'],
- 'is_delete' => 0,
- 'is_pay' => 1
- ];
- $is_scan = 1;
- break;
- }
- $order = $model->where($where)->one();
- if ($order){
- //这里重新方法调用orderYunst来实现分账
- $res = OrderYunst::share($order, $receivers_share1);
- //通联分账
- if ($res['code'] == 0) {
- debug_log('分账成功了');
- debug_log($res);
- $order_id = $res['res']['order_id'];
- SharingReceiver::updateAll(['updated_at' => time(), 'is_pay' => SharingReceiver::PAY_SUCCESS, 'order_id' => $res['res']['order_id']], ['id' => $receivers_share1['id']]);
- $this->saasUserPriceLog($order, [$receivers_share1]);
- $this->saasUserPriceLog($order, [$receivers_share1], true);
- //如果是分账成功自动提现
- // $this->autoCash($order_id);//不在分账后再自动分账,变为每天t+1十点半以后在处理提现
- }else{
- $faildDes = $res['msg'];
- $faildDes && $faildDes = addslashes('(失败:' . $faildDes . ')');
- //分到平台
- if($receivers_share1['type'] == 2){
- if ($is_scan) {
- $order_no = OrderNo::getOrderNo(OrderNo::ORDER_SCAN_CODE_PAY);
- $scan_order = \app\plugins\scanCodePay\models\Order::findOne(['id'=>$order->id]);
- } else {
- $order_no_head = OrderNo::ORDER_ALLIANCE;
- if ($is_mall) {
- $order_no_head = OrderNo::ORDER_MALL;
- }
- $order_no = OrderNo::getOrderNo($order_no_head);
- $scan_order = \app\models\Order::findOne(['id' => $order->id]);
- }
- $scan_order->order_no = $order_no;
- $scan_order->save();
- SharingReceiver::updateAll([
- 'updated_at' => time(),
- 'order_no' => $order_no,
- 'yunst_order_no'=> $res['res']['yunst_order_no'],
- 'is_pay' => SharingReceiver::PAY_FAIL,
- 'err_code' => !empty($res['res']['err_code']) ? $res['res']['err_code'] : $res['msg'],
- 'err_code_des' => !empty($res['res']['err_code_des']) ? $res['res']['err_code_des'] : $res['msg']], ['id' => $receivers_share1['id']]);
- $id = \Yii::$app->cache->get('yunst_receiver_fail_id' . $receivers_share1['id']);
- if ($id && !\Yii::$app->queue->isDone($id)) {
- \Yii::$app->queue->remove($id);
- }
- $id = \queue_push(new \app\jobs\YunstSharingReceiverHandleFailJob(['order_no' => $scan_order->order_no]), 86400);
- \Yii::$app->cache->set('yunst_receiver_fail_id' . $receivers_share1['id'], $id);
- }
- }
- }
- }
- } catch(\Exception $e) {
- // \Yii::error($e);
- debug_log('--------auto-yunst-error---- '.$store->id.' ----auto-yunst-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
- }
- /**
- * 自动提现
- * @return void
- */
- public function autoCash($order_id)
- {
- debug_log('进来了吧哈哈哈');
- $sharing_info = SharingReceiver::find()->where(['order_id' => $order_id, 'is_pay' => SharingReceiver::PAY_SUCCESS])->one();
- if ($sharing_info){
- $order_info = \app\plugins\scanCodePay\models\Order::find()->where(['id' => $sharing_info->order_id])->one();
- if ($order_info){
- // $store_price = $sharing_info->amount; //平台抽用金额
- // $mch_price = ($order_info->pay_price - $sharing_info->amount);//商户实际到账金额
- //因为手续费原因这里提现金额按照商户实际到账金额计算
- $fees = round(($order_info->pay_price * 0.003),2);
- if ($fees){
- $store_price = $sharing_info->amount - $fees; //平台抽用金额
- }else{
- $store_price = $sharing_info->amount ; //平台抽用金额
- }
- $mch_price = ($order_info->pay_price - $sharing_info->amount);//商户实际到账金额
- debug_log($store_price);
- debug_log($mch_price);
- //平台提现
- $cash = new StoreCash();
- $cash->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 0;
- $cash->price = $store_price;
- $cash->created_at = time();
- $cash->store_id = -1;
- $cash->type =6;//通联提现
- $cash->name = '平台提现';
- $cash->mobile = '';
- $cash->pay_time = 0;
- $cash->service_charge = 0;
- $cash->cash_type = 0;
- if ($cash->save()) {
- //调用通联自动提现接口
- $orderYunst = new OrderYunst();
- // $res = $orderYunst->queryAcctInfo('66065100000219T');
- $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value'];
- if ($oldConf) {
- $oldConf = json_decode($oldConf, true);
- if (!empty($oldConf)) {
- $customer_number = $oldConf['customer_number'];
- $res = $orderYunst->queryAcctInfo($customer_number);
- $amount = 0;
- if ($res['subCode'] == 'SUCCESS'){
- $amount = $res['data']['amount'];//真的
- }
- if ($store_price > $amount) {
- debug_log('平台提现金额大于通联账户余额');
- }
- $orderYunst = new OrderYunst();
- $data['bizOrderNo'] = $cash->order_no;
- $data['bizUserId'] = $customer_number;//客户号
- $data['amount'] = intval($cash->price * 100);
- $data['notifyUrl'] = \Yii::$app->request->hostInfo;
- $data['remark'] = "";
- $data['authWay'] = "3";
- $res_cash = $orderYunst->servicerWithdraw($data);
- if ($res_cash['subCode'] != 'SUCCESS'){
- $cash_info2 = StoreCash::findOne($cash->id);
- $order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_info2->order_no = $order_no;
- $cash_info2->save();
- }else{
- $cash_info = StoreCash::findOne($cash->id);
- $cash_info->status = 2;
- $cash_info->pay_time = time();
- $cash_info->save();
- }
- }
- }
- }else{
- debug_log('提现保存失败');
- }
- //商户提现
- $cash_mch = new StoreCash();
- $cash_mch->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_mch->is_delete = 0;
- $cash_mch->status = 0;
- $cash_mch->price = $mch_price;
- $cash_mch->created_at = time();
- $cash_mch->store_id = $sharing_info->store_id;
- $cash_mch->type =6;//通联提现
- $cash_mch->name = '商户提现';
- $cash_mch->mobile = '';
- $cash_mch->pay_time = 0;
- $cash_mch->service_charge = 0;
- $cash_mch->cash_type = 0;
- if ($cash_mch->save()) {
- //调用通联自动提现接口
- $store = \app\models\Store::findOne($sharing_info->store_id);
- $orderYunst = new OrderYunst();
- $res2 = $orderYunst->queryAcctInfo($store->store_number);
- debug_log($res2);
- $amount2 = 0;
- if ($res2['subCode'] == 'SUCCESS'){
- $amount2 = $res2['data']['amount'];//真的
- }
- if ($mch_price > $amount2) {
- debug_log('平台提现金额大于通联账户余额');
- }
- $orderYunst = new OrderYunst();
- $data2['bizOrderNo'] = $cash_mch->order_no;
- $store = Store::findOne(['id' => $cash_mch->store_id]);
- $data2['bizUserId'] = $store->store_number;
- $data2['amount'] = intval($cash_mch->price * 100);
- $data2['notifyUrl'] = \Yii::$app->request->hostInfo;
- $data2['remark'] = "";
- $data2['authWay'] = "3";
- debug_log($data2);
- $res_cash2 = $orderYunst->servicerWithdraw($data2);
- debug_log($res_cash2);
- if ($res_cash2['subCode'] != 'SUCCESS'){
- debug_log('商户提现失败');
- debug_log($res_cash2['subMsg']);
- $cash_info2 = StoreCash::findOne($cash_mch->id);
- $order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_info2->order_no = $order_no;
- $cash_info2->save();
- }else{
- $cash_info2 = StoreCash::findOne($cash_mch->id);
- $cash_info2->status = 2;
- $cash_info2->pay_time = time();
- $cash_info2->save();
- debug_log('商户提现成功');
- }
- }else{
- debug_log('提现保存失败2');
- }
- }else{
- debug_log('订单不存在,提现失败');
- }
- }else{
- debug_log('分账不存在,提现失败');
- }
- }
- private function saasUserPriceLog($order, $SharingReceivers = [], $expend = false, $log = '') {
- try {
- $log_type = SaasUserPriceLog::LOG_TYPE_INCOME;
- $remark = '';
- if($expend){
- $log_type = SaasUserPriceLog::LOG_TYPE_EXPEND;
- $remark = '-分账成功';
- }
- $log && $remark = $log;
- foreach ($SharingReceivers as $item) {
- \Yii::warning(['---- saasUserPriceLog Err11 ----', $item]);
- if(in_array($item['type'], [SharingReceiver::RECEIVE_MERCHANT_ID])){
- continue;
- }
- $desc = $item['remark'] . $remark;
- $saas_id = $item['saas_id'];
- if(!$saas_id){
- if(!$order->is_platform){
- $saas_id = $item['user_id'];
- }else{
- $userInfo = User::findOne($item['user_id']);
- if(!empty($userInfo)){
- $saas = SaasUser::findOne(['mobile' => $userInfo->binding]);
- $saas_id = $saas->id;
- }
- }
- }
- \Yii::warning(['---- saasUserPriceLog Err22 ----', $saas_id, $item['amount'], $item['from'], $log_type, $order->order_no, $desc]);
- SaasUserPriceLog::saveLog($saas_id, $item['amount'], $item['from'], $log_type, $order->order_no, $desc);
- }
- } catch (\Exception $e) {
- \Yii::warning('---- saasUserPriceLog Err ----' . __LINE__);
- }
- }
- /**
- * 自动提现
- * @return void
- */
- public function actionAutoCashNew()
- {
- $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value'];
- $queue_id = \queue_push(new YunstAutoCashJob(['retry' => 5]), 60);
- if ($oldConf){
- $oldConf = json_decode($oldConf, true);
- if (!empty($oldConf)) {
- $customer_number = $oldConf['customer_number'];
- //查询平台余额
- $orderYunst = new OrderYunst();
- $res = $orderYunst->queryAcctInfo($customer_number);
- debug_log($res);
- $store_amount = 0;
- if ($res['subCode'] == 'SUCCESS'){
- $store_amount = $res['data']['amount'];//真的
- }
- if ($store_amount) {
- $cash = new StoreCash();
- $cash->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 0;
- $cash->price = $store_amount/100;
- $cash->created_at = time();
- $cash->store_id = -1;
- $cash->type =6;//通联提现
- $cash->name = '平台提现';
- $cash->mobile = '';
- $cash->pay_time = 0;
- $cash->service_charge = 0;
- $cash->cash_type = 0;
- if ($cash->save()) {
- //调用通联自动提现接口
- $orderYunst = new OrderYunst();
- $data['bizOrderNo'] = $cash->order_no;
- $data['bizUserId'] = $customer_number;//客户号
- $data['amount'] = ceil(bcmul($cash->price, 100));
- $data['notifyUrl'] = \Yii::$app->request->hostInfo;
- $data['remark'] = "";
- $data['authWay'] = "3";
- debug_log($data);
- $res_cash = $orderYunst->servicerWithdraw($data);
- debug_log($res_cash);
- if ($res_cash['subCode'] != 'SUCCESS'){
- debug_log('平台提现失败');
- debug_log($res_cash['subMsg']);
- $cash_info2 = StoreCash::findOne($cash->id);
- $order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_info2->order_no = $order_no;
- $cash_info2->save();
- }else{
- $cash_info = StoreCash::findOne($cash->id);
- $cash_info->status = 2;
- $cash_info->pay_time = time();
- $cash_info->save();
- debug_log('平台提现成功');
- }
- }else{
- debug_log('提现保存失败');
- }
- }else{
- debug_log('平台提现金额不足');
- }
- }
- }
- // 商城列表
- $store_list = Store::find()->where(['is_delete' => 0])->andWhere(['!=','cusid',''])->asArray()->all();
- foreach($store_list as $store) {
- try {
- $orderYunst = new OrderYunst();
- $res2 = $orderYunst->queryAcctInfo($store['store_number']);
- $mch_amount = 0;
- if ($res2['subCode'] == 'SUCCESS'){
- $mch_amount = $res2['data']['amount'];//真的
- }
- // print_r($mch_amount/100);die;
- if ($mch_amount) {
- $cash_mch = new StoreCash();
- $cash_mch->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_mch->is_delete = 0;
- $cash_mch->status = 0;
- $cash_mch->price = $mch_amount/100;
- $cash_mch->created_at = time();
- $cash_mch->store_id = $store['id'];
- $cash_mch->type =6;//通联提现
- $cash_mch->name = '商户提现';
- $cash_mch->mobile = '';
- $cash_mch->pay_time = 0;
- $cash_mch->service_charge = 0;
- $cash_mch->cash_type = 0;
- if ($cash_mch->save()) {
- $orderYunst = new OrderYunst();
- $data2['bizOrderNo'] = $cash_mch->order_no;
- $data2['bizUserId'] = $store['store_number'];
- $data2['amount'] = ceil(bcmul($cash_mch->price, 100));
- $data2['notifyUrl'] = \Yii::$app->request->hostInfo;
- $data2['remark'] = "";
- $data2['authWay'] = "3";
- debug_log($data2);
- $res_cash2 = $orderYunst->servicerWithdraw($data2);
- debug_log($res_cash2);
- if ($res_cash2['subCode'] != 'SUCCESS'){
- debug_log('商户提现失败');
- debug_log($res_cash2['subMsg']);
- $cash_info2 = StoreCash::findOne($cash_mch->id);
- $order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash_info2->order_no = $order_no;
- $cash_info2->save();
- }else{
- $cash_info2 = StoreCash::findOne($cash_mch->id);
- $cash_info2->status = 2;
- $cash_info2->pay_time = time();
- $cash_info2->save();
- debug_log('商户提现成功');
- }
- }else{
- debug_log('提现保存失败2');
- }
- }else{
- debug_log('商户可用余额不足');
- }
- } catch(\Exception $e) {
- \Yii::error('--------auto-execute-cash-error---- '.$store->id.' ----auto-execute-cash-error--------' . $e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
- if ($queue_id && !\Yii::$app->queue->isDone($queue_id)) {
- \Yii::$app->queue->remove($queue_id);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '执行完毕'
- ]);
- }
- }
|