| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\constants\OptionSetting;
- use app\models\Cash;
- use app\models\StoreCash;
- use app\models\StoreAccountLog;
- use app\models\Admin;
- use app\models\Form;
- use app\models\IntegralSetting;
- use app\models\Option;
- use app\models\Store;
- use app\models\StoreTemplate;
- use app\models\SaasCategory;
- use app\models\StoreCopy;
- use app\modules\admin\models\SubmitFormForm;
- use app\utils\Delivery\Delivery;
- use app\utils\yunst\src\OrderYunst;
- use Yii;
- use app\modules\admin\models\StoreForm;
- use app\modules\admin\models\SaasCategoryForm;
- use yii\base\BaseObject;
- use app\models\SaasUser;
- use app\models\Salesman;
- use yii\helpers\Json;
- use app\utils\IotCloudHelper;
- use app\constants\Kefu;
- use app\models\Supplier;
- class StoreCashController extends BaseController
- {
- public function actionTestCash() {
-
- $data = [
- 'partner_trade_no' => 'CStest001',
- 'openid' => 'or1pO5f5zi-atTmKVuni3KGgvCns',
- 'check_name' => 'NO_CHECK',
- 'amount' => 0.01 * 100,
- 'desc' => '转账'
- ];
- $wechat = \Yii::$app->controller->wechatPay;
- $res = $wechat->transfer->toBalance($data);
- var_dump($res);die;
- }
- //商城余额信息
- public function actionStoreMoney() {
- $store_id = get_store_id();
- $store = \app\models\Store::findOne($store_id);
- $data = [];
- //商城总金额
- $maxMoney = StoreCash::getMaxCash($store, $data);
- //已提现
- $moneyCash = StoreCash::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'status' => 2, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])
- ->andWhere(['>', 'price', 0])
- ->sum('price');
- $user_cash = Cash::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'status' => 2])
- ->andWhere(['>', 'price', 0])
- ->sum('price') ?: '0.00';
- $yunst_money = 0;
- $yunst_frozen_money = 0;
- $yunst_store_money_total = 0;
- if ($store->cusid){
- //查询余额账户信息
- $orderYunst = new OrderYunst();
- $res = $orderYunst->queryAcctInfo($store->store_number);
- // $res = $orderYunst->queryAcctInfo('XDQXCJSZPJYB');
- if ($res['subCode']=='SUCCESS' ){
- $freezenAmount = $res['data']['freezenAmount'];//冻结
- $amount = $res['data']['amount'];//可用余额
- if (($freezenAmount + $amount) >0){
- $yunst_store_money_total = ($freezenAmount + $amount) / 100;//累计
- }else{
- $yunst_store_money_total = 0;//累计
- }
- $yunst_frozen_money = $freezenAmount?$freezenAmount/100:0;;//冻结
- $yunst_money = $amount?$amount/100:0;//账户总金额 可提现的
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => [
- 'max_cash' => $maxMoney,
- 'moneyFrozen' => $data['moneyFrozen'],
- 'moneyCash' => $moneyCash ?: '0.00',
- 'moneyTotal' => bcadd($data['storeMoneyTotal'], $yunst_store_money_total, 2),
- 'user_cash' => $user_cash,
- 'yunst_money' => $yunst_money ?: '0.00',
- 'yunst_frozen_money' => $yunst_frozen_money ?: '0.00',
- 'yunst_store_money_total' => $yunst_store_money_total
- ]
- ]);
- }
-
- //saas余额信息
- public function actionSaasMoney() {
- $data = [];
- $moneyCash = StoreCash::find()->where(['store_id' =>'-1', 'is_delete' => 0, 'status' => 2, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])
- ->andWhere(['>', 'price', 0])
- ->sum('price');
- //查询saas余额账户信息
- $orderYunst = new OrderYunst();
- $store_id = get_store_id();
- $store = \app\models\Store::findOne($store_id);
- // $res = $orderYunst->queryAcctInfo($store->store_number);
- // $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);
- if ($res['subCode']=='SUCCESS' ){
- $freezenAmount = $res['data']['freezenAmount'];//冻结
- $amount = $res['data']['amount'];//可用余额
- if (($freezenAmount + $amount) >0){
- $storeMoneyTotal = ($freezenAmount + $amount ) / 100 + $moneyCash;
- }else{
- $storeMoneyTotal = 0;
- }
- $data['moneyFrozen'] = $freezenAmount?$freezenAmount/100:0;;//冻结
- $data['storeMoneyTotal'] = $storeMoneyTotal;//累计
- $maxMoney = $amount?$amount/100:0;//账户总金额 可提现的
- }
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => [
- 'max_cash' => $maxMoney,
- 'moneyFrozen' => $data['moneyFrozen'],
- 'moneyCash' => $moneyCash,
- 'moneyTotal' => $data['storeMoneyTotal'],
- ]
- ]);
- }
- //商城提现删除
- public function actionStoreCashDel() {
- $id = post_params('id');
- if (empty($id) || !is_array($id)) {
- \Yii::error([__METHOD__, $id]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据格式错误'
- ]);
- }
- $del = StoreCash::updateAll(['is_delete' => 1], ['id' => $id]);
- return $this->asJson([
- 'code' => $del ? 0 : 1 ,
- 'msg' => '删除数量:' . $del,
- ]);
- }
- //商城提现
- public function actionStoreCashCreate() {
- $price = post_params('cash');
- $type = post_params('type');
- $name = post_params('name');
- $mobile = post_params('mobile');
- $bank_name = post_params('bank_name');
- if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat','yunst'])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数非法',
- ]);
- }
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- if ($store->cusid){
- $orderYunst = new OrderYunst();
- $res = $orderYunst->queryAcctInfo($store->store_number);
- $amount = 0;
- if ($res['subCode'] == 'SUCCESS'){
- $amount = $res['data']['amount'];//真的
- // $amount = 10;//写的假的
- }
- if ($price > $amount) {
- \Yii::error([__METHOD__, $price, $amount]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前大于可提现金额'
- ]);
- }
- }else{
- //商城余额是否充足
- $storeMoney = \app\models\StoreCash::getMaxCash($store);
- if ($price > $storeMoney) {
- \Yii::error([__METHOD__, $price, $storeMoney]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前大于可提现金额'
- ]);
- }
- }
- $exit = StoreCash::find()->andWhere(['=', 'status', 0])->andWhere(['store_id' => $store_id, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])->exists();
- if ($exit) {
- \Yii::error([__METHOD__, $store_id, $exit]);
- // return $this->asJson([
- // 'code' => 1,
- // 'msg' => '尚有未完成的提现申请'
- // ]);
- }
- $t = \Yii::$app->db->beginTransaction();
- $cash = new StoreCash();
- $cash->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 0;
- $cash->price = $price;
- $cash->created_at = time();
- $cash->store_id = $store_id;
- if ($type == 'wechat') {
- $cash->type = 0;
- $cash->name = $name;
- $cash->mobile = $mobile;
- }
- if ($type == 'alipay') {
- $cash->type = 1;
- $cash->name = $name;
- $cash->mobile = $mobile;
- }
- if ($type == 'bank_card') {
- $cash->type = 2;
- $cash->name = $name;
- $cash->mobile = $mobile;
- $cash->bank_name = $bank_name;
- }
- if ($type == 'yunst') {
- $cash->type =6;//通联提现
- $cash->name = $name;
- $cash->mobile = $mobile;
- }
- $cash->pay_time = 0;
- $cash->service_charge = 0;
- $cash->cash_type = 0;
- if ($cash->save()) {
- $subMoney = \app\models\Store::subMoney($store, $price, '商城提现');
- if (!$subMoney) {
- $t->rollBack();
- \Yii::error([__METHOD__, $subMoney, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '扣款失败',
- ]);
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '申请成功'
- ]);
- } else {
- \Yii::error([__METHOD__, $cash]);
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => $cash->errors
- ]);
- }
- }
- //平台提现
- public function actionSaasCashCreate() {
- $price = post_params('cash');
- $type = post_params('type');
- $store_id = get_store_id();
- $name = post_params('name');
- $mobile = post_params('mobile');
- $bank_name = post_params('bank_name');
- if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat','yunst'])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数非法',
- ]);
- }
- $orderYunst = new OrderYunst();
- $store_id = get_store_id();
- $store = \app\models\Store::findOne($store_id);
- $res = $orderYunst->queryAcctInfo($store->store_number);
- // $res = $orderYunst->queryAcctInfo('XDQXCJSZPJYB');
- debug_log($res);
- $amount = 0;
- if ($res['subCode'] == 'SUCCESS'){
- $amount = $res['data']['amount'];//真的
- // $amount = 10;//写的假的
- }
- if ($price > $amount) {
- \Yii::error([__METHOD__, $price, $amount]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前大于可提现金额'
- ]);
- }
- $exit = StoreCash::find()->andWhere(['=', 'status', 0])->andWhere(['store_id' => -1, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])->exists();
- if ($exit) {
- // return $this->asJson([
- // 'code' => 1,
- // 'msg' => '尚有未完成的提现申请'
- // ]);
- }
- $t = \Yii::$app->db->beginTransaction();
- $order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $orderYunst = new OrderYunst();
- $data['bizOrderNo'] = $order_no;
- $store = Store::findOne(['id' => $store_id]);
- $data['bizUserId'] = $store->store_number;
- // $data['bizUserId'] = "XDQXCJSZPJYB";//测试服务端客户号
- $data['amount'] = $price * 100;
- $data['notifyUrl'] = Yii::$app->request->hostInfo;
- $data['remark'] = "";
- $data['authWay'] = "3";
- $res_cash = $orderYunst->servicerWithdraw($data);
- debug_log($res_cash);
- if ($res_cash['subCode'] != 'SUCCESS'){
- return $this->asJson([
- 'code' => 1,
- 'msg' =>$res_cash['subMsg']
- ]);
- }else{
- $cash = new StoreCash();
- $cash->order_no = \app\utils\OrderNo::getOrderNo(\app\utils\OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 2;
- $cash->price = $price;
- $cash->created_at = time();
- $cash->store_id = -1;
- $cash->type =6;//通联提现
- $cash->name = $name;
- $cash->mobile = $mobile;
- $cash->pay_time = time();
- $cash->service_charge = 0;
- $cash->cash_type = 0;
- if ($cash->save()) {
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '提现成功'
- ]);
- } else {
- \Yii::error([__METHOD__, $cash]);
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => $cash->errors
- ]);
- }
- }
- }
- /**
- * 提现列表
- * @return \yii\web\Response
- */
- public function actionCashList() {
- $store_id = get_params('store_id', 0);
- $export = get_params('export');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $status = get_params('status');
- $type = get_params('type');
- $cash_store_id = get_params('cash_store_id');
- $audit_start_time = get_params('audit_start_time');
- $audit_end_time = get_params('audit_end_time');
- $query = StoreCash::find()->alias('c')->where(['c.is_delete' => 0]);
- // $store_id > 0 && $query->andWhere(['c.store_id' => $store_id]);
- ($type >= 0 && $type != '') && $query->andWhere(['c.type' => $type]);
- if ($start_time) {
- $query->andWhere(['>=', 'c.created_at', strtotime($start_time)]);
- }
- if ($end_time) {
- $query->andWhere(['<=', 'c.created_at', strtotime($end_time)]);
- }
- if ($cash_store_id > 0) {
- $query->andWhere(['c.store_id' => $cash_store_id]);
- }
- if ($store_id <= 0) {
- // $query->andWhere(['c.store_id' => [0, -1]]);
- } else {
- $query->andWhere(['c.store_id' => $store_id]);
- }
- if ($audit_start_time) {
- $query->andWhere(['>=', 'c.updated_at', strtotime($audit_start_time)]);
- }
- if ($audit_end_time) {
- $query->andWhere(['<=', 'c.updated_at', strtotime($audit_end_time)]);
- }
- if ($status == StoreCash::STATUS_APPLY) { //待审核
- $query->andWhere(['c.status' => StoreCash::STATUS_APPLY]);
- }
- if ($status == StoreCash::STATUS_CONFIRM) { // 待打款
- $query->andWhere(['c.status' => StoreCash::STATUS_CONFIRM]);
- }
- if ($status == StoreCash::STATUS_GIVEN) { // 已打款
- $query->andWhere(['in', 'c.status', [StoreCash::STATUS_GIVEN, StoreCash::STATUS_RECHARGE]]);
- }
- if ($status == StoreCash::STATUS_REFUSE) { // 已拒绝
- $query->andWhere(['c.status' => StoreCash::STATUS_REFUSE]);
- }
- $query->orderBy('c.id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$value){
- $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
- $value['money'] = StoreCash::getServiceMoney($value);
- if (!$cash_store_id) {
- $store = Store::findOne($value['store_id']);
- $value['store_name'] = $store->name;
- $value['store_logo'] = $store->logo;
- $value['store_cat_name'] = '-';
- if ($store['category_id'] > 0) {
- $cat = SaasCategory::findOne($store['category_id']);
- if ($cat) {
- $value['store_cat_name'] = $cat->name;
- }
- }
- }
- }
- if($export){
- return $this->export($list);
- }
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- //商城余额是否充足
- $storeMoney = \app\models\StoreCash::getMaxCash($store);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- 'store_cash_money' => $storeMoney ?: '0.00'
- ],
- ]);
- }
- private function export($list) {
- $rows = [[
- 'ID',
- '提现金额(元)',
- '提现方式',
- '提现账号',
- '提现姓名',
- '提现开户行',
- '时间',
- '说明',
- '状态',
- ]];
- foreach($list as $item){
- $r = [
- $item['id'],
- $item['price'],
- StoreCash::getTypeName($item),
- $item['mobile'],
- $item['name'],
- $item['bank_name'],
- date('Y-m-d H:i:s', $item['created_at']),
- $item['reject_reason'],
- StoreCash::getStatusName($item),
- ];
- $rows[] = $r;
- }
- $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
- ->addRows($rows)->toBrowser();
- }
- /**
- * 提现申请审核
- * @return \yii\web\Response
- */
- public function actionCashApply()
- {
- $id = post_params('id');
- $status = post_params('status');
- $reject_reason = input_params('reject_reason', '');
- if (empty($id) || !is_array($id)) {
- \Yii::error([__METHOD__, $id]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据格式错误'
- ]);
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($id as $value) {
- $cash = StoreCash::findOne(['id' => $value, 'is_delete' => StoreCash::IS_DELETE_NO]);
- if (!$cash) {
- $t->rollBack();
- \Yii::error([__METHOD__, $value, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现记录不存在,请刷新重试'
- ]);
- }
- if (!$cash->order_no) {
- $order_no = null;
- while (true) {
- $order_no = date('YmdHis') . mt_rand(100000, 999999);
- $exist_order_no = StoreCash::find()->where(['order_no' => $order_no])->exists();
- if (!$exist_order_no) {
- break;
- }
- }
- $cash->order_no = $order_no;
- $cash->save();
- }
- if (!in_array($status, [1, 3])) {
- $t->rollBack();
- \Yii::error([__METHOD__, $status, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现记录ID: ' . $value . '已审核,请刷新重试'
- ]);
- }
- $store = Store::findOne($cash->store_id);
- $cash->status = $status;
- $cash->reject_reason = $reject_reason;
- if ($status == StoreCash::STATUS_REFUSE && $cash->cash_type == StoreCash::CASH_TYPE_NORMAL) {
- $addMoney = \app\models\Store::addMoney($store, $cash->price, '商城提现-驳回');
- if (!$addMoney) {
- \Yii::error([__METHOD__, $addMoney, $cash]);
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '网络异常,addMoney失败'
- ]);
- }
- }
- if ($status == StoreCash::STATUS_REFUSE && $cash->cash_type == StoreCash::CASH_TYPE_ALLIANCE_COUPON) {
- $store = Store::findOne($cash->store_id);
- $before = $store->league_price;
- $store->updateCounters(['league_price' => floatval($cash->price)]);
- \app\models\SaaSLeaguePriceLog::setLeaguePriceLog(
- $store->id,
- $cash->saas_id,
- $cash->price,
- $before,
- \app\models\SaaSLeaguePriceLog::TYPE_WITHDRAW_REJECT,
- \app\models\SaaSLeaguePriceLog::SEND_TYPE,
- \app\models\SaaSLeaguePriceLog::ROLE_STORE,
- $cash->id
- );
- }
- if (!$cash->save()) {
- \Yii::error([__METHOD__, $cash]);
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '网络异常,请刷新重试'
- ]);
- }
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '审核成功'
- ]);
- }
- /**
- * 打款
- * @return \yii\web\Response
- */
- public function actionCashConfirm()
- {
- $id = post_params('id');
- $cash = StoreCash::findOne(['id' => $id, 'is_delete' => StoreCash::IS_DELETE_NO]);
- if (!$cash) {
- \Yii::error([__METHOD__, $id, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现记录不存在,请刷新重试'
- ]);
- }
- if (!$cash->order_no) {
- $order_no = null;
- while (true) {
- $order_no = date('YmdHis') . mt_rand(100000, 999999);
- $exist_order_no = StoreCash::find()->where(['order_no' => $order_no])->exists();
- if (!$exist_order_no) {
- break;
- }
- }
- $cash->order_no = $order_no;
- $cash->save();
- }
- if ($cash->status != 1) {
- \Yii::error([__METHOD__, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作错误,请刷新重试'
- ]);
- }
- // 微信自动打款
- if ($cash->type == 4) {
- try {
- $storeAdmin = Admin::findOne([
- 'type' => 'store',
- 'type_id' => $cash->store_id,
- 'is_delete' => 0,
- ]);
- if (!$storeAdmin) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '商城绑定的管理员不存在,操作失败'
- ]);
- }
- $saasUser = SaasUser::findOne($storeAdmin->saas_user_id);
- if (!$saasUser) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '商城绑定的管理员不存在,操作失败'
- ]);
- }
- if (empty($saasUser->platform_open_id_merchant)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '商城绑定的管理员open_id不存在,操作失败'
- ]);
- }
-
- $data = [
- 'partner_trade_no' => $cash->order_no,
- 'openid' => $saasUser->platform_open_id_merchant,
- 'check_name' => 'NO_CHECK',
- 'amount' => $cash->price * 100,
- 'user_name' => $cash->name,
- 'desc' => '商城提现'
- ];
- $wechat = getServiceClientWxConfig();
- $res = (new \app\utils\WechatMerchant\WxV3($wechat))->transferBatches(0, $data);
- if ($res['code'] == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $res['msg'],
- ]);
- }
- $cash->wx_cash_type = Cash::WX_CASH_TYPE_NEW;
- $cash->wx_cash_state = $res['data']['state'];
- $cash->wx_cash_result_info = json_encode($res['data'], JSON_UNESCAPED_UNICODE);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败,保存失败' . $e->getMessage()
- ]);
- }
- }
- // 通联提现打款
- if ($cash->type == 6) {
- $store = Store::findOne(['id' => $cash->store_id]);
- if ($store->cusid){
- $orderYunst = new OrderYunst();
- $data['bizOrderNo'] = $cash->order_no;
- $data['bizUserId'] = $store->store_number;
- // $data['bizUserId'] = "XDQXCJSZPJYB";
- $data['amount'] = ceil($cash->price * 100);
- $data['notifyUrl'] = Yii::$app->request->hostInfo;
- $data['remark'] = "";
- $data['authWay'] = "3";
- debug_log('平台审核提现通联');
- debug_log($data);
- $res = $orderYunst->servicerWithdraw($data);
- debug_log($res);
- if ($res['subCode'] != 'SUCCESS'){
- $order_no = date('YmdHis') . mt_rand(100000, 999999);
- $cash->order_no = $order_no;
- $cash->save();
- return $this->asJson([
- 'code' => 1,
- 'msg' =>$res['subMsg']
- ]);
- }
- }
- }
- //手动打款
- $cash->status = StoreCash::STATUS_GIVEN;
- $cash->pay_time = time();
- $cash->pay_type = StoreCash::PAY_TYPE_HAND;
- // NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '手动打款', ($cash->price - $price));
- $save = $cash->save();
- if ($save) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功'
- ]);
- } else {
- \Yii::error([__METHOD__, $cash]);
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败,保存失败'
- ]);
- }
- }
- /**
- * 商城账户明细列表
- * @return \yii\web\Response
- */
- public function actionStoreAccountLogList() {
- $store_id = get_params('store_id');
- $opt = get_params('opt');
- $export = get_params('export');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $cash_store_id = get_params('cash_store_id');
- $type = get_params('type');
- $query = StoreAccountLog::find()->alias('c');
- $store_id > 0 && $query->andWhere(['c.store_id' => $store_id]);
- if ($start_time) {
- $query->andWhere(['>=', 'c.time', strtotime($start_time)]);
- }
- if ($end_time) {
- $query->andWhere(['<=', 'c.time', strtotime($end_time)]);
- }
- if ($cash_store_id) {
- $query->andWhere(['c.store_id' => $cash_store_id]);
- }
- if ($type > 0) {
- $query->andWhere(['c.type' => $type]);
- }
- if($opt == 1){
- $query->andWhere(['like', 'c.desc', '商城提现']);
- }
- $query->orderBy('c.id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$value){
- if (!$cash_store_id) {
- $store = Store::findOne($value['store_id']);
- $value['store_name'] = $store->name;
- $value['store_logo'] = $store->logo;
- $value['store_cat_name'] = '-';
- if ($store['category_id'] > 0) {
- $cat = SaasCategory::findOne($store['category_id']);
- if ($cat) {
- $value['store_cat_name'] = $cat->name;
- }
- }
- }
- }
- if($export){
- return $this->exportStoreAccountLog($list);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- private function exportStoreAccountLog($list) {
- $rows = [[
- 'ID',
- '余额类型',
- '变动金额(元)',
- '变动前',
- '变动后',
- '时间',
- '说明',
- ]];
- foreach($list as $item){
- $r = [
- $item['id'],
- $item['type'] == 1 ? '收入' : '支出',
- $item['price'],
- $item['before'],
- $item['after'],
- date('Y-m-d H:i:s', $item['time']),
- $item['desc'],
- ];
- $rows[] = $r;
- }
- $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
- ->addRows($rows)->toBrowser();
- }
- }
|