[ 'status_0' => [ 'text' => '待付款', 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-0.png', ], 'status_1' => [ 'text' => '待发货', 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-1.png', ], 'status_2' => [ 'text' => '待收货', 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-2.png', ], 'status_3' => [ 'text' => '已完成', 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-3.png', ], 'status_4' => [ 'text' => '售后', 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-4.png', ], ] ]; return $data; } public function actionGetUserPrice() { $saasUser = get_saas_user(); if (!$saasUser) { return $this->asJson([ 'code' => 1, 'msg' => "参数解析错误" ]); } $data = [ 'share_profit' => $saasUser->share_profit, 'name' => $saasUser->name, 'avatar' => $saasUser->avatar ]; return $this->asJson($data); } public function actionGetCategoryInfo() { $list = \app\models\SaasCategory::findAll(['is_delete' => 0]); return $this->asJson([ 'code' => 0, 'data' => $list, ]); } /** * 用户中心 * @return \yii\web\Response */ public function actionIndex() { $data = $this->getDefaultData(); $data = [ 'code' => 0, 'data' => $data, 'msg' => 'success' ]; $saasUser = get_saas_user(); $is_admin = 0; $is_store_admin = 0; if ($saasUser) { $is_admin = !empty($saasUser->id) ? Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type'=>"admin"]) : ""; // 根据admin表中手机号判断当前是否为客户端管理员,后期需添加admin表中的手机号编辑 $store_admin = Admin::find()->where(['mobile' => $saasUser->mobile, 'is_delete' => 0, 'type' => 'store'])->orderBy('id DESC')->one(); if($store_admin){ $is_store_admin = Store::findOne(['id' => $store_admin->type_id, 'is_delete' => 0]); }else{ $is_store_admin = ''; } } $storeCloud = StoreCloud::find() ->where(['is_delete' => 0, 'is_enable' => 1, 'saas_user_id' => $saasUser['id']]) ->one(); $is_can_distribution = $storeCloud && $storeCloud->store_id > 0 ? 1 : 0;// 是否有商城(是否可以铺货) $is_can_distribution = $is_can_distribution && $storeCloud['can_distribution'] ? 1 : 0;// 否具备 一键铺货选品的权限 //店铺积分 $store_integral = User::find()->alias('u')->leftJoin(['s' => Store::tableName()], 'u.store_id = s.id') ->where(['u.is_delete' => 0, 's.is_delete' => 0, 'binding' => $saasUser->mobile])->andWhere(['IS NOT', 's.id', NULL])->sum('u.integral') ?: 0; $user_data_info = [ 'access_token' => $saasUser['access_token'], 'avatar_url' => $saasUser['avatar'], 'binding' => $saasUser['mobile'], 'id' => $saasUser['id'], 'nickname' => $saasUser['name'], 'saas_money' => $saasUser['share_profit'], 'is_salesman' => $saasUser['is_salesman'], 'is_admin' => empty($is_admin) ? 0 : 1, 'is_store_admin' => empty($is_store_admin) ? 0 : 1, 'gender' => $saasUser['gender'], 'is_purchase' => $storeCloud ? 1 : 0, // 是否为采购员 'is_can_distribution' => $is_can_distribution, // 是否有商城(是否可以铺货) 'can_distribution' => $storeCloud['can_distribution'] ?? 0, // 否具备 一键铺货选品的权限 'league_price' => $saasUser->league_price, 'integral' => $saasUser->integral, 'store_integral' => $store_integral ]; $data['data']['user_info'] = $user_data_info; /** * 获取用户优惠券数量 */ $coupon_num = SaasCoupon::find()->where([ 'saas_id' => get_saas_user_id(), 'is_delete' => 0, 'is_use' => 0, 'is_expire' => 0, ])->count(); /** * 获取浏览记录数量(包含商品和店铺的总数) */ $browse_log_num = BrowseLog::find()->where([ 'saas_id' => get_saas_user_id(), //'store_id' => get_store_id(), 'is_delete' => 0, ])->count(); /** * 获取用户收藏商品数量 */ $favorite_goods_num = Favorite::find()->where([ 'saas_id' => get_saas_user_id(), 'is_delete' => 0 ])->count(); $order_count = OrderListForm::getCountData(get_saas_user_id()); $distribution = SaasDistribution::findOne(['saas_id' => get_saas_user_id()]); $is_distribution = false; if (is_wechat_platform()) { if (!empty($distribution->platform_open_id)) { $is_distribution = true; } } if (is_alipay_platform()) { if (empty($distribution->ali_name)) { $is_distribution = true; } } // start 获取核销码 // TODO 这里要做支付宝小程序兼容 $code_url = ''; if (isset($data['data']['user_info'])) { $data['data']['user_info']['is_can_wechat'] = 0; if (strpos($data['data']['user_info']['nickname'], '****') !== false) { $data['data']['user_info']['is_can_wechat'] = 1; } } $arr = [ 'code' => 0, 'msg' => 'success', 'data' => [ 'order_count' => $order_count, 'show_customer_service' => 1, 'user_info' => isset($data['data']['user_info']) ? $data['data']['user_info'] : null, 'orders' => $data['data']['orders'], 'coupon_num' => $coupon_num, 'favorite_goods_num' => $favorite_goods_num, 'browse_log_num' => $browse_log_num, 'code_url' => $code_url, 'is_distribution' => $is_distribution ], ]; return $this->asJson($arr); } /** * 会员支付 */ public function actionSubmitMember() { $form = new OrderMemberForm(); $form->saas_id = get_saas_user_id(); $form->attributes = post_params(); return $this->asJson($form->save()); } /** * 支付 * @return \yii\web\Response */ public function actionMemberPayData() { $form = new BusinessMemberOrderPayDataForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * 假支付 * @return \yii\web\Response */ public function actionFpay(){ $pay_price = get_params('price',0); $code = get_params('code'); // $type = get_params('type'); $goods_names = '测试支付'; $form = new BusinessMemberOrderPayDataForm(); return $this->asJson($form->falsePay($goods_names, $pay_price, $code)); } /** * 设为默认收货地址 * @return \yii\web\Response */ public function actionAddressSetDefault() { $form = new AddressSetDefaultForm(); $form->attributes = get_params(); $form->store_id = $this->alliance_store_id; $form->user_id = get_saas_user_id(); return $this->asJson($form->save()); } /** * 收货地址详情 * @return \Yii\web\Response */ public function actionAddressDetail() { $form = new AddressSetDefaultForm(); $form->address_id = get_params('id'); $form->store_id = $this->alliance_store_id; $form->user_id = get_saas_user_id(); return $this->asJson($form->info()); } /** * 删除收货地址 * @return \yii\web\Response */ public function actionAddressDelete() { $form = new AddressSetDefaultForm(); $form->attributes = get_params(); $form->store_id = $this->alliance_store_id; $form->user_id = get_saas_user_id(); return $this->asJson($form->delete()); } /** * 保存收货地址 * @return \yii\web\Response */ public function actionAddressSave() { $form = new AddressSaveForm(); $form->attributes = post_params(); $form->store_id = $this->alliance_store_id; $form->user_id = get_saas_user_id(); return $this->asJson($form->save()); } /** * 获取收货地址 * @return \yii\web\Response */ public function actionAddressList() { $query = Address::find()->where([ 'is_delete' => 0, 'user_id' => get_saas_user_id(), ]); $list = $query->orderBy('is_default DESC,addtime DESC')->select('id,name,mobile,province_id,province,city_id,city,district_id,district,detail,is_default')->asArray()->all(); foreach ($list as $i => $item) { $list[$i]['address'] = $item['province'] . $item['city'] . $item['district'] . $item['detail']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, ], ]); } /** * 获取信息 * @return \yii\web\Response */ public function actionOcrInfo() { $type = post_params('type'); if (empty($type) || !in_array($type, OcrApi::$validType)) { return $this->asJson([ 'code' => 1, 'msg' => '类型参数错误' ]); } $side = post_params('side'); if (empty($side) && $type == OcrApi::TYPE_ID_CARD) { return $this->asJson([ 'code' => 1, 'msg' => '身份证参数有误' ]); } $url = post_params('url'); if (empty($url)) { return $this->asJson([ 'code' => 1, 'msg' => '图片地址为空' ]); } try { $ocr = new OcrApi(true); switch ($type) { case OcrApi::TYPE_LICENSE: $res = $ocr->getBusinessLicense($url); break; case OcrApi::TYPE_ID_CARD: $res = $ocr->getIDCard($url, $side); break; case OcrApi::TYPE_BANK: $res = $ocr->getBankCard($url); break; case OcrApi::TYPE_TEXT: $res = $ocr->getTextRecognition($url, 1); break; } if ($res['code'] == 0 && !empty($res['data'])) { return $this->asJson($res); } return $this->asJson([ 'code' => 1, 'msg' => '获取信息失败,请手动输入' ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionOtherInfo() { $cloud_supplier_banner = Option::get('cloud_supplier_banner', 0, 'saas', '')['value']; $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value']; $cloud_supplier_apply_agreement = Option::get('cloud_supplier_apply_agreement', 0, 'saas', '')['value']; $supplier_custom_form = Option::get('supplier_custom_form', 0, 'saas', json_encode([]))['value']; return $this->asJson([ 'code' => 0, 'data' => [ 'cloud_supplier_banner' => $cloud_supplier_banner ? Json::decode($cloud_supplier_banner) : [], 'store_apply_agreement' => $admin_copyright, 'cloud_supplier_apply_agreement' => $cloud_supplier_apply_agreement, 'supplier_custom_form' => json_decode($supplier_custom_form), ] ]); } /** * 联盟佣金提现提交 */ public function actionCashCommit() { $amount = post_params('amount'); if ($amount < 0.01) { return $this->asJson([ 'code' => 1, 'msg' => '提现最小金额不能小于0.01元' ]); } $user = !empty(get_user()) ? get_user() : User::find()->where(['binding'=>get_saas_user()->mobile])->one(); $saas_user = SaasUser::findOne(['mobile' => $user->binding]); if ($saas_user->share_profit < $amount) { return $this->asJson([ 'code' => 1, 'msg' => '当前提现金额大于可提现联盟佣金' ]); } if (!$saas_user->platform_open_id) { return $this->asJson([ 'code' => 1, 'msg' => '请先绑定平台小程序openid' ]); } $t = \Yii::$app->db->beginTransaction(); $cash = new SaasProfitCash(); $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_SAAS_PROFIT_CASH); $cash->user_id = get_saas_user_id(); $cash->mobile = $user->binding; $cash->amount = $amount; $cash->status = SaasProfitCash::CASH_STATUS_WAIT; $cash->created_at = time(); if (!$cash->save()) { return $this->asJson([ 'code' => 1, 'msg' => $cash->errors[0] ]); } $cash->before_price = $saas_user->share_profit; $cash->after_price = ($saas_user->share_profit - $amount); $saas_user->share_profit = $saas_user->share_profit - $amount; $saas_user->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '提交成功,请等待审核' ]); } /** * 联盟佣金提现列表 */ public function actionCashList() { $page = get_params('page', 1); $limit = get_params('limit', 10); $status = get_params('status', -1); $user = get_user(); $query = SaasProfitCash::find()->where(['mobile' => !empty($user->binding) ? $user->binding : get_saas_user()->mobile]); if ($status > -1) { if ($status <= 2) { $query->andWhere(['status' => $status]); } else { $query->andWhere(['is_pay' => 1]); } } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as &$value) { $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $value['amount'] = sprintf("%.2f", ($value['amount'] - $value['service_money'])); $value['status_text'] = $value['status'] == 0 ? '待审核' : ($value['status'] == 1 ? '已通过' : '已拒绝'); if ($value['status'] == 1 && $value['is_pay'] == 1) { $value['status'] = 4; $value['status_text'] = '已打款'; } $value['updated_at'] = $value['updated_at'] ? date('Y-m-d H:i:s', $value['updated_at']) : null; $value['status'] = (string)$value['status']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } public function actionAddHistory() { $saas_user_id = get_saas_user_id(); if ($saas_user_id > 0) { $store_id = get_store_id(); $history = SaasHistory::find()->where(['user_id' => $saas_user_id, 'store_id' => $store_id])->one(); if ($history) { $history->updated_at = time(); $history->save(); } else { $history = new SaasHistory(); $history->user_id = $saas_user_id; $history->store_id = $store_id; $history->updated_at = time(); $history->save(); } } return $this->asJson([ 'code' => 0, 'msg' => '添加成功', ]); } public function actionGetHistory() { $page = get_params('page', 1); $limit = 10; $query = SaasHistory::find()->alias('sh') ->leftJoin(['s' => Store::tableName()], 'sh.store_id=s.id') ->select(['s.id', 's.name', 's.logo']); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $query->limit($limit)->offset($pagination->offset); $list = $query->orderBy(['sh.updated_at' => SORT_DESC])->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $list, ]); } /** * 喜欢的商品或店铺列表 */ public function actionCheckFavorite() { $is_favorite = Favorite::find()->where(['store_id'=>get_store_id(),'saas_id'=>get_saas_user_id(),'is_delete'=>0])->one(); $storeInfo = Store::find()->where(['id'=>get_store_id(),'is_delete'=>0])->one(); $store_name = ''; if(isset($storeInfo->name)){ $store_name = $storeInfo->name; } $status = (isset($is_favorite->id) && $is_favorite->id > 0) ? 1 : 0; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data'=>[ 'status' => $status, 'store_name' => $store_name ] ]); } /** * 添加商品或店铺到我的喜欢 */ public function actionFavoriteAdd() { $form = new FavoriteAddForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->saas_id = get_saas_user_id(); $form->user_id = 0; return $this->asJson($form->save()); } /** * 喜欢的商品或店铺列表 */ public function actionFavoriteList() { $form = new FavoriteListForm(); $form->attributes = get_params(); $form->saas_id = get_saas_user_id(); $form->user_id = 0; //$form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * 取消喜欢的商品或店铺列表 */ public function actionRemoveFavorite() { $id = get_store_id(); if (empty($id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } // if (!is_array($id)) { // $res = Favorite::updateAll(['is_delete' => 1], ['goods_id' => $id, 'user_id' => get_user_id(), 'type' => post_params('type', 0)]); // } else { // $res = Favorite::updateAll(['is_delete' => 1], ['and', ['in', 'goods_id', $id], ['user_id' => get_user_id(), 'type' => post_params('type', 0)]]); // } $res = Favorite::updateAll(['is_delete' => 1], ['store_id' => $id, 'saas_id' => get_saas_user_id(), 'type' => post_params('type', 0)]); if ($res) { return $this->asJson([ 'code' => 0, 'msg' => '删除成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => 'fail', 'err' => $res ]); } } public function actionSearchKeyword() { $keyword = Option::get('search_keyword', 0, 'saas', json_encode([])); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($keyword['value']), ]); } //获取返利数据 public function actionRebaseInfo(){ $saas_id = get_saas_user_id(); //echo $saas_id;exit; $receiverInfo = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0])->andWhere([ 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]] ])->asArray()->all(); $total = $finish = $nofinish = 0; foreach($receiverInfo as $val){ $total += $val['amount']; if($val['is_pay'] == 0){ $nofinish += $val['amount']; } if($val['is_pay'] == 1){ $finish += $val['amount']; } } $data['total'] = $total; $data['nofinish'] = $nofinish; $data['finish'] = $finish; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data ]); } //获取返利数据 public function actionRebaseList(){ $saas_id = get_saas_user_id(); $status = get_params('status',-1); $page = get_params('page',1); $limit = 10; $query = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0]); if($status == -1){ //全部 $query->andWhere([ 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]] ]); } if($status == 0){ //未到账 $query->andWhere(['is_pay'=>0]); } if($status == 1){ //已到账 $query->andWhere(['is_pay'=>1]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $query->limit($limit)->offset($pagination->offset); $list = $query->orderBy(['id' => SORT_DESC])->select('is_pay,created_at,amount,remark')->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => ['list'=>$list,'page'=>$page,'count'=>$count] ]); } /** * 获取联盟券记录 */ public function actionLeaguePriceLog() { $saas_user_id = get_saas_user()->id; $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']); $store = Store::findOne($admin->type_id); $send_or_take_type = get_params('send_or_take_type', -1); $type = get_params('type', -1); $query = SaaSLeaguePriceLog::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'role' => SaaSLeaguePriceLog::ROLE_STORE]) ->select('id, type, send_or_take_type, league_price, addtime, saas_user_id')->orderBy('addtime desc'); if (isset($send_or_take_type) && $send_or_take_type >= 0) { $query->andWhere(['send_or_take_type' => $send_or_take_type]); } if (isset($type) && in_array($type, [0, 1])) { $query->andWhere(['type' => $type]); } $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']); $item['type'] = (int)$item['type']; $item['send_or_take_type'] = (int)$item['send_or_take_type']; $item['name'] = ''; $item['mobile'] = ''; $item['avatar'] = ''; if ($item['saas_user_id']) { $saasUser = SaasUser::findOne($item['saas_user_id']); if ($saasUser) { $item['name'] = $saasUser->name; $item['mobile'] = $saasUser->mobile; $item['avatar'] = $saasUser->avatar; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'] ] ]); } /** * 个人分账记录 * @return \yii\web\Response */ public function actionShareProfitRecord() { $page = get_params('page', 1); $limit = get_params('limit', 10); $saasUser = get_saas_user(); $query = SharingReceiver::find()->where(['saas_id' => $saasUser->id]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as $key => $value) { $tmp = []; $tmp['order_no'] = $value['order_no']; $tmp['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $tmp['amount'] = $value['amount']; $tmp['remark'] = $value['remark']; $tmp['pay_status'] = $value['is_pay'] == 0 ? '待分账' : ($value['is_pay'] == 1 ? '已分账' : '分账失败-转佣金'); $list[$key] = $tmp; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } }