| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers;
- use app\jobs\StoreSyncJob;
- use app\models\Admin;
- use app\models\Cash;
- use app\models\Option;
- use app\models\SaasUser;
- use app\modules\admin\models\OrderRefundForm;
- use app\modules\admin\models\OrderSendForm;
- use app\modules\alliance\behaviors\StoreUserAdmin;
- use app\modules\alliance\controllers\BaseController;
- use app\modules\alliance\models\ShareQrcodeForm;
- use app\modules\alliance\models\store\StoreAdminCommentForm;
- use app\modules\alliance\models\store\StoreAdminForm;
- use app\modules\alliance\models\store\StoreAdminGoodsForm;
- use app\modules\alliance\models\store\StoreAdminUserForm;
- use app\modules\alliance\models\store\StoreAdminOrderForm;
- use app\modules\alliance\controllers\store\Controller;
- use app\utils\yunst\src\OrderYunst;
- use yii\helpers\ArrayHelper;
- use app\models\StoreTemplate;
- use app\models\SaasCategory;
- use app\models\StoreCash;
- use app\models\StoreAccountLog;
- use app\models\Store;
- use app\utils\OrderNo;
- use app\models\SaaSLeaguePriceLog;
- class StoreAdminController extends Controller
- {
- /**
- * @return array
- */
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- [
- 'class' => StoreUserAdmin::class
- ]
- ]);
- }
- /**
- * 商品
- **/
- //管理中心
- public function actionStoreInfo(){
- $form = new StoreAdminForm();
- $form->wechat = $this->wechat;
- $form->store_id = $this->store_id;
- $res = $form->storeInfo();
- return $this->asJson($res);
- }
- //店铺数据
- public function actionShopData()
- {
- $form = new StoreAdminForm();
- $form->start_date = input_params('start_date');
- $form->end_date = input_params('end_date');
- $form->wechat = $this->wechat;
- $form->store_id = $this->store_id;
- $form->tab = input_params('tab');
- $form->type = input_params('type');
- $res = $form->shopData();
- return $this->asJson($res);
- }
- //修改获取商城数据
- public function actionGetStoreInfo()
- {
- $form = new StoreAdminForm();
- $form->logo = post_params('logo');
- $form->name = post_params('name');
- $form->coordinate = post_params('coordinate');
- $form->address = post_params('address');
- $form->store_id = $this->store_id;
- $res = $form->getStoreInfo();
- return $this->asJson($res);
- }
- //店铺数据
- public function actionGetYesData()
- {
- $form = new StoreAdminForm();
- $form->start_date = input_params('start_date');
- $form->end_date = input_params('end_date');
- $form->wechat = $this->wechat;
- $form->store_id = $this->store_id;
- $res = $form->getYesData();
- return $this->asJson($res);
- }
- //用户列表
- public function actionUserList(){
- $form = new StoreAdminUserForm();
- $attributes = all_params();
- $res = $form->userList($this->store_id, $attributes);
- return $this->asJson($res);
- }
- //充值积分或者余额
- public function actionUserRecharge() {
- $form = new StoreAdminUserForm();
- $data = post_params();
- $admin = get_admin();
- // $admin = json_decode(json_encode(['username' => 'uuu', 'id' => 1]));
- return $this->asJson($form->userRecharge($admin, $this->store_id, $data));
- }
- //商品列表
- public function actionGoodsList(){
- $form = new StoreAdminGoodsForm();
- $form->status = get_params('status',1);
- $form->sort = get_params('sort');
- $form->store_id = $this->store_id;
- $res = $form->goodsList();
- return $this->asJson($res);
- }
- //修改标题
- public function actionSetGoodsName(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->goods_name = post_params('name');
- $form->store_id = $this->store_id;
- $res = $form->setGoodsName();
- return $this->asJson($res);
- }
- //删除商品
- public function actionGoodsDel(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->store_id = $this->store_id;
- $res = $form->goodsDel();
- return $this->asJson($res);
- }
- //分享商品
- public function actionShareGoods(){
- $form = new ShareQrcodeForm();
- $form->goods_id = post_params('id');
- $form->type = 0;
- $form->user = get_user();
- $form->user_id = get_user_id();
- $form->store_id = $this->store_id;
- return $this->asJson($form->search());
- }
- //修改上下架状态
- public function actionSetGoodsStatus(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->status = post_params('status');
- $form->store_id = $this->store_id;
- $res = $form->setGoodsStatus();
- return $this->asJson($res);
- }
- //修改价格库存
- public function actionSetGoodsPrice(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->goods_price = post_params('goods_price', 0);
- $form->goods_num = post_params('goods_num', 0);
- $form->attr = post_params('attr', 0);
- $form->store_id = $this->store_id;
- $res = $form->setPrice();
- return $this->asJson($res);
- }
- //获取修改商品数据
- public function actionGetGoodsEdit(){
- $form = new StoreAdminGoodsForm();
- $form->id = get_params('id');
- $form->store_id = $this->store_id;
- $res = $form->getGoodsEdit();
- return $this->asJson($res);
- }
- //获取运费规则
- public function actionGetPostageData(){
- $form = new StoreAdminGoodsForm();
- $res = $form->getPostageData();
- return $this->asJson($res);
- }
- //保存商品
- public function actionSaveGoods(){
- $form = new StoreAdminGoodsForm();
- $form->goods_info = post_params('goods_info');
- $form->store_id = $this->store_id;
- $res = $form->saveGoods();
- return $this->asJson($res);
- }
- //商品详情
- public function actionGoodsDetail(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->store_id = $this->store_id;
- $res = $form->goodsDetail();
- return $this->asJson($res);
- }
- //获取商品规格信息
- public function actionGetGoodsAttr(){
- $form = new StoreAdminGoodsForm();
- $form->id = post_params('id');
- $form->store_id = $this->store_id;
- $res = $form->getGoodsAttr();
- return $this->asJson($res);
- }
- //分类列表
- public function actionCatList() {
- $form = new StoreAdminGoodsForm();
- $form->store_id = $this->store_id;
- $res = $form->catList();
- return $this->asJson($res);
- }
- //分类添加保存
- public function actionCatSave() {
- $form = new StoreAdminGoodsForm();
- $form->cat_name = post_params("name");
- $form->id = post_params("id");
- $form->parent_id = post_params("parent_id", 0);
- $form->pic_url = post_params("pic_url");
- $form->status = post_params("is_show", 1);
- $form->store_id = $this->store_id;
- $res = $form->catAdd();
- return $this->asJson($res);
- }
- //分类添加保存
- public function actionCatBatchSave() {
- $form = new StoreAdminGoodsForm();
- $form->store_id = $this->store_id;
- $res = $form->catAddBatch(input_params("name_1"), input_params("name_2"), input_params("name_3"));
- return $this->asJson($res);
- }
- //分类修改状态
- public function actionSetCatStatus() {
- $form = new StoreAdminGoodsForm();
- $form->id = post_params("id");
- $form->status = post_params("status", 0);
- $form->store_id = $this->store_id;
- $res = $form->setCatStatus();
- return $this->asJson($res);
- }
- /**
- * 订单
- */
- //订单列表
- public function actionOrderList() {
- $form = new StoreAdminOrderForm();
- $form->status = get_params("status");
- $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
- 'begin_time' => get_params("begin_time"),
- 'end_time' => get_params("end_time")
- ];
- $form->store_id = $this->store_id;
- $res = $form->orderList();
- return $this->asJson($res);
- }
- //订单商品评价
- public function actionOrderCommentGoodsList() {
- $form = new StoreAdminCommentForm();
- $form->goods_name = get_params("goods_name");
- $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
- 'begin_time' => get_params("begin_time"),
- 'end_time' => get_params("end_time")
- ];
- $form->store_id = $this->store_id;
- $res = $form->commentGoodsList();
- return $this->asJson($res);
- }
- //订单评价
- public function actionOrderCommentList() {
- $form = new StoreAdminCommentForm();
- $form->goods_name = get_params("goods_name");
- $form->goods_id = get_params("goods_id");
- $form->status = get_params("status");
- $form->type = get_params("type");
- $form->store_id = $this->store_id;
- $res = $form->commentList();
- return $this->asJson($res);
- }
- //删除评论
- public function actionCommentDel() {
- $form = new StoreAdminCommentForm();
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->commentDel();
- return $this->asJson($res);
- }
- //回复评论
- public function actionCommentReply() {
- $form = new StoreAdminCommentForm();
- $form->id = post_params("id");
- $form->reply_content = post_params("reply_content");
- $form->store_id = $this->store_id;
- $res = $form->commentReply();
- return $this->asJson($res);
- }
- //取消订单
- public function actionOrderCancel() {
- $form = new StoreAdminOrderForm();
- $form->remark = post_params("remark");
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->orderCancel();
- return $this->asJson($res);
- }
- //拒绝取消订单
- public function actionOrderRejectCancel() {
- $form = new StoreAdminOrderForm();
- // $form->remark = post_params("remark");
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->orderRejectCancel();
- return $this->asJson($res);
- }
- //订单发货
- public function actionOrderSend() {
- $form = new OrderSendForm();
- $post = post_params();
- if (($post['is_express'] == OrderSendForm::EXPRESS_TYPE_EXPRESS)) {
- $form->scenario = 'EXPRESS';
- }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_DADA){
- $form->scenario = 'DADA';
- }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_UU){
- $form->scenario = 'UU';
- }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_PEISONG){
- $form->scenario = 'PEISONG';
- }
- $form->attributes = $post;
- $form->store_id = $this->store_id;
- return $this->asJson($form->save());
- }
- //售后订单
- public function actionOrderRefund() {
- $form = new StoreAdminOrderForm();
- $form->status = get_params("status", 0);
- $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
- 'begin_time' => get_params("begin_time"),
- 'end_time' => get_params("end_time")
- ];
- $form->store_id = $this->store_id;
- $res = $form->orderRefund();
- return $this->asJson($res);
- }
- //订单详情
- public function actionOrderDetail() {
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->type = post_params("type", 0);
- $form->store_id = $this->store_id;
- $res = $form->orderDetail();
- return $this->asJson($res);
- }
- //获取快递公司数据
- public function actionGetExpress(){
- $form = new StoreAdminOrderForm();
- $form->store_id = $this->store_id;
- $res = $form->express();
- return $this->asJson($res);
- }
- //售后订单处理
- public function actionOrderRefundApply() {
- $form = new OrderRefundForm();
- $form->order_refund_id = post_params("id");
- $form->store_id = $this->store_id;
- $form->action = post_params("action", 0);
- $form->type = post_params("type", 1);
- $form->refund = post_params("refund", 0);
- $form->address_id = post_params("address_id", 0);
- $res = $form->save();
- return $this->asJson($res);
- }
- //售后地址添加
- public function actionRefundAddressSave() {
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->mch_name = post_params("name");
- $form->mch_mobile = post_params("mobile");
- $form->mch_address = post_params("address");
- $form->is_default = post_params("is_default", 0);
- $form->store_id = $this->store_id;
- $res = $form->refundAddressSave();
- return $this->asJson($res);
- }
- //商家收货地址列表
- public function actionRefundAddress() {
- $form = new StoreAdminOrderForm();
- $form->store_id = $this->store_id;
- $res = $form->refundAddress();
- return $this->asJson($res);
- }
- //商家收货地址删除
- public function actionRefundAddressDel() {
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->refundAddressDel();
- return $this->asJson($res);
- }
- //商家收货地址设置默认
- public function actionRefundAddressDefault(){
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->refundAddressDefault();
- return $this->asJson($res);
- }
- //设置订单中的收货地址
- public function actionSetRefundAddress(){
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $form->mch_address = post_params("address_id");
- $res = $form->setRefundAddress();
- return $this->asJson($res);
- }
- //获取单个收货地址
- public function actionGetAddressInfo(){
- $form = new StoreAdminOrderForm();
- $form->id = post_params("id");
- $form->store_id = $this->store_id;
- $res = $form->getAddressInfo();
- return $this->asJson($res);
- }
- /**
- * 批量修改价格
- */
- public function actionUpPriceBatch()
- {
- $goods_id = input_params('goods_id');
- $num = input_params('num');
- $form = new \app\modules\admin\models\GoodsForm();
- $res = $form->upPriceBatch($goods_id, $num, 'add');
- return $this->asJson($res);
- }
- public function actionTemplateList()
- {
- $name = input_params('name', '');
- $category_id = input_params('category_id', 0);
- $cond = ['is_delete' => 0, 'status' => 1];
- $name && $cond['name'] = $name;
- $category_id && $cond['category_id'] = $category_id;
- $query = StoreTemplate::find()->where($cond);
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$item){
- $item['cat_name'] = '-';
- if ($item['category_id'] > 0) {
- $cat = SaasCategory::findOne($item['category_id']);
- if ($cat) {
- $item['cat_name'] = $cat->name;
- }
- }
- $item['home_pic'] = json_decode($item['home_pic'], true);
- $item['center_pic'] = json_decode($item['center_pic'], true);
-
- }
- $store_template_used = \app\models\Option::get('store_template_used', $this->store_id, 'saas', 0)['value'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'store_template_used' => $store_template_used,
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- 'sql' => '111'.$query->createCommand()->getRawSql(),
- ],
- ]);
- }
- public function actionTemplateInfo()
- {
- $store_id = $this->store_id;
- $id = input_params('id', 0);
- $model = StoreTemplate::findOne($id);
- $store_template_used = \app\models\Option::get('store_template_used', $store_id, 'saas', 0)['value'];
- $used = $store_template_used == $model->id ? 1 : 0;
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $model,
- 'used' => $used,
- ]);
- }
- public function actionTemplateUsed()
- {
- $store_id = $this->store_id;
- $id = input_params('id', 0);
- $type = input_params('type', ['home']);//home/category/product/center/all
- $model = StoreTemplate::findOne($id);
- $useTemp = $model->useTemp($store_id, $type);
- if($useTemp['code'] != 0){
- return $this->asJson($useTemp);
- }
-
- if(in_array('all', $type)){
- \app\models\Option::set('store_template_used', $id, $store_id, 'saas');
- $model->use_count++;
- $model->save();
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $model,
- 'copy' => $useTemp,
- ]);
- }
- public function actionStoreCopyStatus()
- {
- $id = input_params('id', 0);
- $res = \app\models\StoreCopy::doCopyStatus($id);
- return $this->asJson($res);
- }
- //店铺初始化
- public function actionStoreInit()
- {
- $id = input_params("id", 0);
- $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
- if($default){
- $default = json_decode($default, true);
- }else{
- return $this->asJson([
- 'code' => 0,
- 'msg' => '暂无默认模板',
- ]);
- }
-
- // $res = \app\models\StoreCopy::doCopy($default['store_id'], $id, $default['type']);
- // return $this->asJson($res);
- $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $id]), 0, 1);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- }
- /**
- * 获取提现方式
- */
- public function actionGetCashMethod()
- {
- $saas_user = get_saas_user();
- $cash_method = [];
- if (!empty($saas_user->withdraw_method)) {
- $decode = json_decode($saas_user->withdraw_method, true);
- if (is_array($decode)) {
- $cash_method = $decode;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $cash_method,
- ],
- ]);
- }
- /**
- * 获取提现方式
- */
- public function actionDelCashMethod()
- {
- $saas_user = get_saas_user();
- $type = post_params('type');
- if (empty($type)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误',
- ]);
- }
- if (empty($saas_user->withdraw_method)) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- }
- $cash_method = json_decode($saas_user->withdraw_method, true);
- if (is_array($cash_method)) {
- foreach ($cash_method as $key => $value) {
- if ($value['type'] == $type) {
- unset($cash_method[$key]);
- }
- }
- $saas_user->withdraw_method = json_encode(array_values($cash_method));
- } else {
- $saas_user->withdraw_method = '';
- }
- if ($saas_user->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作失败',
- ]);
- }
- /**
- * 添加提现方式
- */
- public function actionAddCashMethod()
- {
- $type = post_params('type');
- if (empty($type)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误',
- ]);
- }
- $name = post_params('name');
- $account = post_params('account');
- $bank = post_params('bank');
- if (empty($name) || empty($account)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '账号和姓名不能为空',
- ]);
- }
- if ($type == 'bank_card' && empty($bank)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '银行不能为空',
- ]);
- }
- $data = [
- 'type' => $type,
- 'name' => $name,
- 'account' => $account,
- ];
- if ($type == 'bank_card') {
- $data['bank'] = $bank;
- }
- $saas_user = get_saas_user();
- if (empty($saas_user->withdraw_method)) {
- $saas_user->withdraw_method = json_encode(array_values([$data]));
- } else {
- $decode = json_decode($saas_user->withdraw_method, true);
- if (!$decode) {
- $saas_user->withdraw_method = json_encode(array_values([$data]));
- } else {
- foreach ($decode as $key => $value) {
- if ($value['type'] == $type) {
- unset($decode[$key]);
- break;
- }
- }
- $decode[] = $data;
- $saas_user->withdraw_method = json_encode(array_values($decode));
- }
- }
- if ($saas_user->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败',
- ]);
- }
- // 联盟券提现
- private function allianceCouponWithdraw($store, $price, $type)
- {
- if ($price > $store->league_price) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现金额不能大于联盟券余额',
- ]);
- }
- $user_id = get_user_id();
- $t = \Yii::$app->db->beginTransaction();
- try {
- $cash = new StoreCash();
- $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 0;
- $cash->price = $price;
- $cash->created_at = time();
- $cash->user_id = $user_id;
- $cash->store_id = $store->id;
- $saas_user = get_saas_user();
- $cash->saas_id = $saas_user->id;
- $withdraw_method = json_decode($saas_user->withdraw_method, true);
- if ($withdraw_method) {
- $withdraw_method = array_column($withdraw_method, null, 'type');
- if ($type == 'wechat') {
- $cash->type = 0;
- $cash->name = $withdraw_method['wechat']['name'];
- $cash->mobile = $withdraw_method['wechat']['account'];
- }
- if ($type == 'alipay') {
- $cash->type = 1;
- $cash->name = $withdraw_method['alipay']['name'];
- $cash->mobile = $withdraw_method['alipay']['account'];
- }
- if ($type == 'bank_card') {
- $cash->type = 2;
- $cash->name = $withdraw_method['bank_card']['name'];
- $cash->mobile = $withdraw_method['bank_card']['account'];
- $cash->bank_name = $withdraw_method['bank_card']['bank'];
- }
- }
-
- if ($type == 'wechat_auto') {
- $cash->type = 4; // 微信自动打款
- }
- $cash->pay_time = 0;
- $cash->cash_type = StoreCash::CASH_TYPE_ALLIANCE_COUPON;
- if (!$cash->save()) {
- throw new \Exception('申请失败');
- }
- $before = $store->league_price;
- $store->updateCounters(['league_price' => -floatval($price)]);
- \app\models\SaaSLeaguePriceLog::setLeaguePriceLog(
- $store->id,
- $cash->saas_id,
- $cash->price,
- $before,
- \app\models\SaaSLeaguePriceLog::TYPE_WITHDRAW,
- \app\models\SaaSLeaguePriceLog::TAKE_TYPE,
- \app\models\SaaSLeaguePriceLog::ROLE_STORE,
- $cash->id
- );
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '申请成功',
- ]);
- } catch (\Exception $e) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '申请失败',
- ]);
- }
- }
- //商城账户提现申请
- public function actionCashApply() {
- $price = post_params('cash');
- $type = post_params('type');
- $scene = post_params('scene');
- if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat', 'wechat_auto'])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数非法',
- ]);
- }
- $user_id = get_user_id();
- $user = get_user();
- $store_id = $this->store_id;
- $store = Store::findOne($store_id);
- if (!$store) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数非法',
- ]);
- }
- if ($scene == 'allianceCoupon') { // 联盟券提现
- return $this->allianceCouponWithdraw($store, $price, $type);
- }
- 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 = OrderNo::getOrderNo(OrderNo::ORDER_CASH);
- $cash->is_delete = 0;
- $cash->status = 0;
- $cash->price = $price;
- $cash->created_at = time();
- $cash->user_id = $user_id;
- $cash->store_id = $store_id;
- $saas_user = get_saas_user();
- $cash->saas_id = $saas_user->id;
- $withdraw_method = json_decode($saas_user->withdraw_method, true);
- if ($withdraw_method) {
- $withdraw_method = array_column($withdraw_method, null, 'type');
- if ($type == 'wechat') {
- $cash->type = 0;
- $cash->name = $withdraw_method['wechat']['name'];
- $cash->mobile = $withdraw_method['wechat']['account'];
- }
- if ($type == 'alipay') {
- $cash->type = 1;
- $cash->name = $withdraw_method['alipay']['name'];
- $cash->mobile = $withdraw_method['alipay']['account'];
- }
- if ($type == 'bank_card') {
- $cash->type = 2;
- $cash->name = $withdraw_method['bank_card']['name'];
- $cash->mobile = $withdraw_method['bank_card']['account'];
- $cash->bank_name = $withdraw_method['bank_card']['bank'];
- }
- }
-
- if ($type == 'wechat_auto') {
- $cash->type = 4; // 微信自动打款
- }
- $cash->pay_time = 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 {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => $cash->errors
- ]);
- }
- }
- /**
- * 提现明细
- * @return \yii\web\Response
- */
- public function actionCashDetail() {
- $status = get_params('status', -1);
- $saasUser = get_saas_user();
- $store_id = $this->store_id;
- $cash_type = get_params('cash_type', 0);
- if ($cash_type) {
- $admin = Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type' => Admin::ADMIN_TYPE_STORE]);
- $store = Store::findOne(['id' => $admin->type_id, 'is_delete' => 0]);
- $store_id = $store->id;
- }
- $query = StoreCash::find()->where(['store_id' => $store_id, 'is_delete' => 0]);
- if ($status > -1) {
- // 待审核
- if ($status == 0) {
- $query->andWhere(['status' => $status]);
- }
- // 已审核
- if ($status == 1) {
- $query->andWhere(['status' => $status]);
- }
- // 已打款
- if ($status == 2) {
- $query->andWhere(['in', 'status', [2, 4]]);
- }
- // 已拒绝
- if ($status == 3) {
- $query->andWhere(['status' => $status]);
- }
- }
- if (intval($cash_type)) {
- $query->andWhere(['cash_type' => $cash_type]);
- }
- $query->orderBy('id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach ($list as &$value) {
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['audit_time'] = date('Y-m-d H:i:s', $value['updated_at']);
- if ($value['status'] == 2 || $value['status'] == 4) {
- $value['audit_time'] = date('Y-m-d H:i:s', $value['pay_time']);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ]
- ]);
- }
- /**
- * 获取提现详情
- */
- public function actionCashDetailInfo()
- {
- $id = get_params('id');
- $store_cash = StoreCash::findOne($id);
- if (!$store_cash) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现记录不存在'
- ]);
- }
- // $wechat = getServiceClientWxConfig();
- // if (!$wechat) {
- // return $this->asJson([
- // 'code' => 1,
- // 'msg' => '未开启微信提现功能'
- // ]);
- // }
- $platform_mch_appid = Option::get('platform_mch_appid', 0, 'saas')['value'];
- $platform_mch_id = Option::get('platform_mch_id', 0, 'saas')['value'];
- // $serial_no = Option::get('platform_mch_api_serial_no', 0, 'saas')['value'];
- // if (empty($serial_no)) {
- // return $this->asJson([
- // 'code' => 1,
- // 'msg' => '未开启微信提现功能'
- // ]);
- // }
- $saasUser = null;
- $name = $store_cash->name ?: '';
- if (intval($store_cash->type) === StoreCash::TYPE_WECHAT_AUTO) {
- $storeAdmin = Admin::findOne([
- 'type' => 'store',
- 'type_id' => $store_cash->store_id,
- 'is_delete' => 0,
- ]);
- if ($storeAdmin) {
- $saasUser = SaasUser::findOne($storeAdmin->saas_user_id);
- if ($saasUser) {
- $name = $saasUser->name;
- }
- }
- }
- $package = '';
- if (!empty($store_cash->wx_cash_result_info)) {
- $wx_cash_result_info = json_decode($store_cash->wx_cash_result_info, true);
- $package = $wx_cash_result_info['package_info'];
- }
- $is_user_confirm = 1;
- $status = $store_cash->status;
- //如果是微信提现且为自动打款
- if ($store_cash->type == StoreCash::TYPE_WECHAT_AUTO && $store_cash->status == Cash::STATUS_GIVEN) {
- //如果使用的是微信新版打款方式
- if (1 || intval($store_cash->wx_cash_type)) {
- //如果微信新版状态是等待用户确认
- if ($store_cash->wx_cash_state == 'WAIT_USER_CONFIRM') {
- $is_user_confirm = 0;
- if ($saasUser->id != get_saas_user_id()) {
- $is_user_confirm = 1;
- }
- // $status = Cash::STATUS_CONFIRM;
- }
- }
- }
- $price = StoreCash::getServiceMoney($store_cash);
- $data = [
- 'type' => StoreCash::$type[$store_cash->type],//提现方式
- 'status' => $status,//提现状态
- 'order_no' => $store_cash->order_no,
- 'created_at' => date('Y-m-d H:i:s', $store_cash->created_at),
- 'updated_at' => $store_cash->updated_at > 0 ? date('Y-m-d H:i:s', $store_cash->updated_at) : '',
- 'name' => $name,
- 'appid' => $platform_mch_appid,
- 'mch_id' => $platform_mch_id,
- 'package' => $package,
- 'is_user_confirm' => $is_user_confirm,
- 'price' => $price,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- //商城账户余额信息
- public function actionStoreMoney() {
- $store_id = $this->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');
- $yunstFreeZenAmount = 0;
- $yunstMaxMoney = 0;
- $yunstMoneyTotal = 0;
- if ($store->cusid){
- //查询余额账户信息
- $orderYunst = new OrderYunst();
- // print_r(111);die;
- $res = $orderYunst->queryAcctInfo($store->store_number);
- // $res = $orderYunst->queryAcctInfo('XDQXCJSZPJYB');
- // print_r($res);die;
- if ($res['subCode']=='SUCCESS' ){
- // print_r($res);die;
- $yunstFreeZenAmount = $res['data']['freezenAmount'];//冻结
- $amount = $res['data']['amount'];//可用余额
- if (($yunstFreeZenAmount + $amount) >0){
- $yunstMoneyTotal = ($yunstFreeZenAmount + $amount) / 100;
- }else{
- $yunstMoneyTotal = 0;
- }
- $yunstFreeZenAmount = $yunstFreeZenAmount? $yunstFreeZenAmount/100 : 0;;//冻结
- $yunstMaxMoney = $amount?$amount/100:0;//账户总金额 可提现的
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => [
- 'max_cash' => $maxMoney,//总计提现
- 'moneyFrozen' => $data['moneyFrozen'],//冻结金额
- 'moneyCash' => $moneyCash,//可提现
- 'moneyTotal' => bcadd($data['storeMoneyTotal'], $yunstMoneyTotal, 2),//累计金额
- 'yunstFreeZenAmount' => $yunstFreeZenAmount,//通联冻结
- 'yunstMaxMoney' => $yunstMaxMoney,//通联账户总金额
- 'yunstMoneyTotal' => $yunstMoneyTotal, //通联冻结+账户可提现
- 'league_price' => $store->league_price,
- ]
- ]);
- }
- /**
- * 商城账户明细列表
- * @return \yii\web\Response
- */
- public function actionStoreAccountLogList() {
- $store_id = $this->store_id;
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $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 ($type > 0) {
- $query->andWhere(['c.type' => $type]);
- }
- $query->orderBy('c.id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- /**
- * 获取商城溢价
- */
- public function actionStoreSetting() {
- $form = new StoreAdminForm();
- $form->store_id = $this->store_id;
- $form->rate = post_params('rate');
- // $form->is_auth_trans = post_params('is_auth_trans');
- $form->cloud_is_update = post_params('cloud_is_update');
- $res = $form->storeSetting();
- return $this->asJson($res);
- }
- //核销支付宝商家券
- public function actionClerkAlipayVoucher() {
- $form = new \app\modules\admin\models\alipay\Ordervoucher();
- $form->mini_id = get_mini_id();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $total_price = post_params('total_price', 100);
- $ov = post_params('ov', '');
- $submit = post_params('submit', 1);
- $res = $form->use($submit, $ov, $total_price);
- return $this->asJson($res);
- }
- //扫码入库
- public function actionErpScanGetGoodsList() {
- $form = new StoreAdminGoodsForm();
- $form->attributes = get_params();
- $form->store_id = $this->store_id;
- $res = $form->erpScanGetGoodsList();
- return $this->asJson($res);
- }
- //erp入库
- public function actionPurchaseInSave() {
- $form = new StoreAdminGoodsForm();
- $form->attributes = all_params();
- $form->store_id = $this->store_id;
- $res = $form->purchaseInSave();
- return $this->asJson($res);
- }
- }
|