| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace app\jobs;
- use app\constants\OptionSetting;
- use app\models\Option;
- use app\models\Order;
- use app\models\SaasUser;
- use app\models\SaasUserPriceLog;
- use app\models\SharingReceiver;
- use app\models\Store;
- use app\models\StoreCash;
- use app\models\User;
- use app\utils\OrderNo;
- use app\utils\yunst\src\OrderYunst;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- //通联支付提现失败
- class YunstAutoCashJob extends BaseObject implements JobInterface
- {
- public $retry;
- public function execute($queue)
- {
- if ($this->retry > 0) {
- $queue_id = \queue_push(new YunstAutoCashJob(['retry' => $this->retry--]), 900);
- }
- $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'];
- //查询平台余额
- $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'] = "";
- $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'] = "";
- $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 (isset($queue_id) && !\Yii::$app->queue->isDone($queue_id)) {
- \Yii::$app->queue->remove($queue_id);
- }
- return [
- 'code' => 0,
- 'msg' => '执行完毕'
- ];
- }
- }
|