// +---------------------------------------------------------------------- namespace app\wap\controller; use app\wap\model\user\SmsCode; use app\wap\model\store\StoreOrderCartInfo; use app\wap\model\store\StorePink; use app\wap\model\store\StoreProductReply; use app\wap\model\store\StoreService; use app\wap\model\store\StoreServiceLog; use app\wap\model\store\StoreCart; use app\wap\model\store\StoreCategory; use app\wap\model\store\StoreOrder; use app\wap\model\store\StoreProduct; use app\wap\model\store\StoreProductAttr; use app\wap\model\store\StoreProductRelation; use app\wap\model\user\User; use app\wap\model\user\UserAddress; use app\wap\model\user\UserBill; use app\wap\model\user\UserExtract; use app\wap\model\user\UserRecharge; use app\wap\model\user\UserNotice; use app\wap\model\user\UserSign; use app\wap\model\user\SignPoster; use app\wap\model\user\WechatUser; use behavior\wap\StoreProductBehavior; use service\AliMessageService; use service\WechatTemplateService; use service\CacheService; use service\HookService; use service\JsonService; use service\SystemConfigService; use service\GroupDataService; use service\UtilService; use service\WechatService; use think\Cache; use think\Request; use think\Session; use think\Url; use app\wap\model\user\MemberShip; use app\wap\model\user\MemberCard;//会员卡 use app\wap\model\user\MemberCardBatch;//会员卡批次 use service\sms\storage\Sms; class AuthApi extends AuthController { public static function WhiteList() { return [ 'code' ]; } public function upload() { $aliyunOss = \Api\AliyunOss::instance([ 'AccessKey' => SystemConfigService::get('accessKeyId'), 'AccessKeySecret' => SystemConfigService::get('accessKeySecret'), 'OssEndpoint' => SystemConfigService::get('end_point'), 'OssBucket' => SystemConfigService::get('OssBucket'), 'uploadUrl' => SystemConfigService::get('uploadUrl'), ]); $res = $aliyunOss->upload('file'); if ($res) { return JsonService::successful('上传成功', ['url' => $res['url']]); } else { return JsonService::fail('上传失败'); } } /** * 发送短信验证码 * @param string $phone */ public function code($phone = '') { $name = "is_phone_code" . $phone; if ($phone == '') return JsonService::fail('请输入手机号码!'); $time = Session::get($name, 'wap'); if ($time < time() + 60) Session::delete($name, 'wap'); if (Session::has($name, 'wap') && $time < time()) return JsonService::fail('您发送验证码的频率过高,请稍后再试!'); $code = AliMessageService::getVerificationCode(); SmsCode::set(['tel' => $phone, 'code' => $code, 'last_time' => time() + 300, 'uid' => $this->uid]); Session::set($name, time() + 60, 'wap'); $smsHandle = new Sms(); $sms_platform_selection=SystemConfigService::get('sms_platform_selection'); $smsSignName=SystemConfigService::get('smsSignName');//短信模板ID $smsTemplateCode=SystemConfigService::get('smsTemplateCode');//短信模板ID if($sms_platform_selection==1){ if(!$smsSignName || !$smsTemplateCode) return JsonService::fail('系统后台短信没有配置,请稍后在试!'); $res = AliMessageService::sendmsg($phone, $code); }else{ $res=$smsHandle->send($phone,$smsTemplateCode,['code'=>$code]); } if($res){ return JsonService::successful('发送成功',$res); } else { return JsonService::fail('发送失败!'); } } /** * 用户签到信息 */ public function getUserList(){ $signList = UserSign::userSignInlist($this->userInfo['uid'],1,3); return JsonService::successful($signList); } /** * 签到明细 */ public function getUserSignList($page,$limit){ $signList = UserSign::userSignInlist($this->userInfo['uid'],$page,$limit); return JsonService::successful($signList); } /** * 签到 */ public function user_sign() { $gold_name=SystemConfigService::get('gold_name');//虚拟币名称 $signed = UserSign::checkUserSigned($this->userInfo['uid']); if ($signed) return JsonService::fail('已签到'); if (false !== $gold_coin = UserSign::sign($this->userInfo,$gold_name)){ $poster=SignPoster::todaySignPoster($this->userInfo['uid']); if($poster){ return JsonService::successful('签到获得' . floatval($gold_coin).$gold_name,$poster); }else{ return JsonService::fail('生成海报失败!'); } }else return JsonService::fail('签到失败!'); } /** * 用户信息 */ public function userInfo(){ $user=$this->userInfo; $surplus=0; //会员剩余天数 $time=bcsub($user['overdue_time'],time(),0); if($user['level']>0 && $time>0) $surplus=bcdiv($time,86400,2); $user['surplus']=ceil($surplus); return JsonService::successful($user); } /** * 商品退款原因 */ public function refund_reason() { $goods_order_refund_reason=GroupDataService::getData('goods_order_refund_reason') ?:[]; return JsonService::successful($goods_order_refund_reason); } /** * 会员页数据 */ public function merberDatas(){ $interests=GroupDataService::getData('membership_interests',3)?:[]; $description=GroupDataService::getData('member_description')?:[]; $interests_sort = array_column($interests,'sort'); array_multisort($interests_sort,SORT_ASC,$interests); $description_sort = array_column($description,'sort'); array_multisort($description_sort,SORT_ASC,$description); $data['interests']=$interests; $data['description']=$description; $data['member']=MemberShip::memberMinOne(); return JsonService::successful($data); } /** * 免费会员/是否领取 */ public function isRecord() { $data['freeData']=MemberShip::memberFree($this->userInfo['uid']); return JsonService::successful($data); } /** * 会员设置列表 */ public function membershipLists(){ $meList=MemberShip::membershipList(); return JsonService::successful($meList); } /** * 会员卡激活 */ public function confirm_activation(){ $request = Request::instance(); if (!$request->isPost()) return JsonService::fail('参数错误!'); $data = UtilService::postMore([ ['member_code', ''], ['member_pwd', ''], ], $request); $res=MemberCard::confirmActivation($data,$this->userInfo); if($res) return JsonService::successful('激活成功'); else return JsonService::fail(MemberCard::getErrorInfo('激活失败!')); } /** * 用户领取免费会员 */ public function memberPurchase($id=0){ if(!$id) return JsonService::fail('参数错误!'); $order = StoreOrder::cacheMemberCreateOrder($this->userInfo['uid'],$id,'weixin'); $orderId = $order['order_id']; $info = compact('orderId'); if ($orderId) { $orderInfo = StoreOrder::where('order_id', $orderId)->find(); if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); if ($orderInfo['paid']) exception('支付已支付!'); if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) { if (StoreOrder::jsPayMePrice($orderId, $this->userInfo['uid'])) return JsonService::status('success', '领取成功', $info); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); } else { try { $jsConfig = StoreOrder::jsPayMember($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $info); } $info['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '领取成功', $info); } } else { return JsonService::fail(StoreOrder::getErrorInfo('领取失败!')); } } /**加入购物车 * @param string $productId * @param int $cartNum * @param string $uniqueId */ public function set_cart($productId = '', $cartNum = 1, $uniqueId = '') { if (!$productId || !is_numeric($productId)) return $this->failed('参数错误!'); $res = StoreCart::setCart($this->userInfo['uid'], $productId, $cartNum, $uniqueId, 'product'); if (!$res) return $this->failed(StoreCart::getErrorInfo('加入购物车失败!')); else { HookService::afterListen('store_product_set_cart_after', $res, $this->userInfo, false, StoreProductBehavior::class); return $this->successful('ok', ['cartId' => $res->id]); } } /**加入购物车立即购买 * @param int $productId * @param int $cartNum * @param string $uniqueId */ public function now_buy($productId = 0, $cartNum = 1, $uniqueId = '') { if ($productId == '' || $productId<0) return $this->failed('参数错误!'); $res = StoreCart::setCart($this->userInfo['uid'], $productId, $cartNum, $uniqueId, 'product', 1); if (!$res) return $this->failed(StoreCart::getErrorInfo('加入购物车失败!')); else { return $this->successful('ok', ['cartId' => $res->id]); } } /**点赞 * @param string $productId * @param string $category */ public function like_product($productId = '', $category = 'product') { if (!$productId || !is_numeric($productId)) return $this->failed('参数错误!'); $res = StoreProductRelation::productRelation($productId, $this->userInfo['uid'], 'like', $category); if (!$res) return $this->failed(StoreProductRelation::getErrorInfo('点赞失败!')); else return $this->successful(); } /**取消点赞 * @param string $productId * @param string $category */ public function unlike_product($productId = '', $category = 'product') { if (!$productId || !is_numeric($productId)) return $this->failed('参数错误!'); $res = StoreProductRelation::unProductRelation($productId, $this->userInfo['uid'], 'like', $category); if (!$res) return $this->failed(StoreProductRelation::getErrorInfo('取消点赞失败!')); else return $this->successful(); } /**商品收藏 * @param $productId * @param string $category */ public function collect_product($productId, $category = 'product') { if (!$productId || !is_numeric($productId)) return $this->failed('参数错误!'); $res = StoreProductRelation::productRelation($productId, $this->userInfo['uid'], 'collect', $category); if (!$res) return $this->failed(StoreProductRelation::getErrorInfo('收藏失败!')); else return $this->successful(); } /**商品取消收藏 * @param $productId * @param string $category */ public function uncollect_product($productId, $category = 'product') { if (!$productId || !is_numeric($productId)) return $this->failed('参数错误!'); $res = StoreProductRelation::unProductRelation($productId, $this->userInfo['uid'], 'collect', $category); if (!$res) return $this->failed(StoreProductRelation::getErrorInfo('取消收藏失败!')); else return $this->successful(); } public function get_cart_num() { return JsonService::successful('ok', StoreCart::getUserCartNum($this->userInfo['uid'], 'product')); } public function get_cart_list() { return JsonService::successful('ok', StoreCart::getUserProductCartList($this->userInfo['uid'])); } public function change_cart_num($cartId = '', $cartNum = '') { if (!$cartId || !$cartNum || !is_numeric($cartId) || !is_numeric($cartNum)) return JsonService::fail('参数错误!'); StoreCart::changeUserCartNum($cartId, $cartNum, $this->userInfo['uid']); return JsonService::successful(); } public function remove_cart($ids = '') { if (!$ids) return JsonService::fail('参数错误!'); StoreCart::removeUserCart($this->userInfo['uid'], $ids); return JsonService::successful(); } public function get_user_collect_product($first = 0, $limit = 8) { $list = StoreProductRelation::where('A.uid', $this->userInfo['uid']) ->field('B.id pid,B.store_name,B.price,B.ot_price,B.sales,B.image,B.is_del,B.is_show')->alias('A') ->where('A.type', 'collect')->where('A.category', 'product') ->order('A.add_time DESC')->join('__STORE_PRODUCT__ B', 'A.product_id = B.id') ->limit($first, $limit)->select()->toArray(); foreach ($list as $k => $product) { if ($product['pid']) { $list[$k]['is_fail'] = $product['is_del'] && $product['is_show']; } else { unset($list[$k]); } } return JsonService::successful($list); } public function remove_user_collect_product($productId = '') { if (!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!'); StoreProductRelation::unProductRelation($productId, $this->userInfo['uid'], 'collect', 'product'); return JsonService::successful(); } /**设置默认地址 * @param string $addressId */ public function set_user_default_address($addressId = '') { if (!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!'); if (!UserAddress::be(['is_del' => 0, 'id' => $addressId, 'uid' => $this->userInfo['uid']])) return JsonService::fail('地址不存在!'); $res = UserAddress::setDefaultAddress($addressId, $this->userInfo['uid']); if (!$res) return JsonService::fail('地址不存在!'); else return JsonService::successful(); } /** * 添加和修改地址 */ public function edit_user_address() { $request = Request::instance(); if (!$request->isPost()) return JsonService::fail('参数错误!'); $addressInfo = UtilService::postMore([ ['address', []], ['is_default', false], ['real_name', ''], ['post_code', ''], ['phone', ''], ['detail', ''], ['id', 0] ], $request); $addressInfo['province'] = $addressInfo['address']['province']; $addressInfo['city'] = $addressInfo['address']['city']; $addressInfo['district'] = $addressInfo['address']['district']; $addressInfo['is_default'] = $addressInfo['is_default'] == true ? 1 : 0; $addressInfo['uid'] = $this->userInfo['uid']; unset($addressInfo['address']); if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $this->userInfo['uid'], 'is_del' => 0])) { $id = $addressInfo['id']; unset($addressInfo['id']); if (UserAddress::edit($addressInfo, $id, 'id')) { if ($addressInfo['is_default']) UserAddress::setDefaultAddress($id, $this->userInfo['uid']); return JsonService::successful(); } else return JsonService::fail('编辑收货地址失败!'); } else { if ($address = UserAddress::set($addressInfo)) { if ($addressInfo['is_default']) UserAddress::setDefaultAddress($address->id, $this->userInfo['uid']); return JsonService::successful(); } else return JsonService::fail('添加收货地址失败!'); } } /** * 获取用户所有地址 */ public function user_address_list() { $list=UserAddress::getUserValidAddressList($this->userInfo['uid'], 'id,real_name,phone,province,city,district,detail,is_default'); if ($list) return JsonService::successful('ok', $list); else return JsonService::successful('empty', []); } /** * 获取默认地址 */ public function user_default_address() { $defaultAddress = UserAddress::getUserDefaultAddress($this->userInfo['uid'], 'id,real_name,phone,province,city,district,detail,is_default'); if ($defaultAddress) return JsonService::successful('ok', $defaultAddress); else return JsonService::successful('empty', []); } /**删除地址 * @param string $addressId */ public function remove_user_address($addressId = '') { if (!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!'); if (!UserAddress::be(['is_del' => 0, 'id' => $addressId, 'uid' => $this->userInfo['uid']])) return JsonService::fail('地址不存在!'); if (UserAddress::edit(['is_del' => '1'], $addressId, 'id')) return JsonService::successful(); else return JsonService::fail('删除地址失败!'); } /**获取用户的商品订单列表 * @param string $type * @param int $first * @param int $limit */ public function get_user_order_list($type = 0, $first = 0, $limit = 8) { $list = StoreOrder::getUserOrderList($this->userInfo['uid'], $type, $first, $limit); return JsonService::successful($list); } /** * 用户订单数据 */ public function userOrderDate() { $data=StoreOrder::getOrderStatusNum($this->userInfo['uid']); return JsonService::successful($data); } /**删除订单 * @param string $uni */ public function user_remove_order($uni = '') { if (!$uni) return JsonService::fail('参数错误!'); $res = StoreOrder::removeOrder($uni, $this->userInfo['uid']); if ($res) return JsonService::successful(); else return JsonService::fail(StoreOrder::getErrorInfo()); } /**提交商品退款 * @param string $uni * @param string $text */ public function apply_order_refund($uni = '') { if (!$uni) return JsonService::fail('参数错误!'); $request = Request::instance(); if (!$request->isPost()) return JsonService::fail('参数错误!'); $data = UtilService::postMore([ ['pics', []], ['refund_reason', ''], ['remarks', ''], ], $request); $res = StoreOrder::orderApplyRefund($uni, $this->userInfo['uid'],$data); if ($res) return JsonService::successful(); else return JsonService::fail(StoreOrder::getErrorInfo()); } /**用户确认收货 * @param string $uni */ public function user_take_order($uni = '') { if (!$uni) return JsonService::fail('参数错误!'); $res = StoreOrder::takeOrder($uni, $this->userInfo['uid']); if ($res) return JsonService::successful(); else return JsonService::fail(StoreOrder::getErrorInfo()); } /**虚拟币充值 * @param int $price * @param int $payType */ public function user_wechat_recharge($price = 0,$payType = 0) { if (!$price || $price <= 0 || !is_numeric($price)) return JsonService::fail('参数错误'); if (!isset($this->userInfo['uid']) || !$this->userInfo['uid']) return JsonService::fail('用户不存在'); try { //充值记录 $rechargeOrder = UserRecharge::addRecharge($this->userInfo['uid'], $price, $payType); if (!$rechargeOrder) return JsonService::fail('充值订单生成失败!'); $orderId = $rechargeOrder['order_id']; $goldName = SystemConfigService::get("gold_name"); switch ($payType) { case 'weixin': try { $jsConfig = UserRecharge::jsRechargePay($orderId); } catch (\Exception $e) { return JsonService::status('pay_error', $e->getMessage(), $rechargeOrder); } $rechargeOrder['jsConfig'] = $jsConfig; return JsonService::status('wechat_pay', '订单创建成功', $rechargeOrder); break; case 'yue': if (UserRecharge::yuePay($orderId, $this->userInfo)) return JsonService::status('success', '余额支付成功', $rechargeOrder); else return JsonService::status('pay_error', StoreOrder::getErrorInfo()); break; case 'zhifubao': $rechargeOrder['orderName'] = $goldName."充值"; $rechargeOrder['orderId'] = $orderId; $rechargeOrder['pay_price'] = $price; return JsonService::status('zhifubao_pay','订单创建成功', base64_encode(json_encode($rechargeOrder))); break; } } catch (\Exception $e) { return JsonService::fail($e->getMessage()); } } /**余额明细 * @param int $index * @param int $first * @param int $limit */ public function user_balance_list($index = 0,$first = 0, $limit = 8) { $model = UserBill::where('uid', $this->userInfo['uid'])->where('category', 'now_money') ->where('type','in', 'pay_goods,system_add,pay_product_refund,pay_product,recharge,system_sub,pay_sign_up') ->field('title,mark,pm,number,add_time') ->where('status', 1)->where('number','>',0); switch ($index){ case 1: $model=$model->where('pm',0); break; case 2: $model=$model->where('pm',1); break; } $list=$model->order('add_time DESC')->page((int)$first, (int)$limit)->select(); $list=count($list) >0 ? $list->toArray() : []; foreach ($list as &$v) { $v['add_time'] = date('Y/m/d H:i', $v['add_time']); } return JsonService::successful($list); } /**金币明细 * @param int $index * @param int $first * @param int $limit */ public function user_gold_num_list($index = 0,$first = 0, $limit = 8) { $model = UserBill::where('uid', $this->userInfo['uid'])->where('category', 'gold_num') ->field('title,mark,pm,number,add_time') ->where('status', 1)->where('number','>',0); switch ($index){ case 1: $model=$model->where('pm',0); break; case 2: $model=$model->where('pm',1); break; } $list=$model->order('add_time DESC')->page((int)$first, (int)$limit)->select(); $list=count($list) >0 ? $list->toArray() : []; foreach ($list as &$v) { $v['add_time'] = date('Y/m/d H:i', $v['add_time']); } return JsonService::successful($list); } /** * @param string $unique * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function user_comment_product($unique = '') { if (!$unique) return JsonService::fail('参数错误!'); $cartInfo = StoreOrderCartInfo::where('unique', $unique)->find(); $uid = $this->userInfo['uid']; if (!$cartInfo || $uid != $cartInfo['cart_info']['uid']) return JsonService::fail('评价产品不存在!'); if (StoreProductReply::be(['oid' => $cartInfo['oid'], 'unique' => $unique])) return JsonService::fail('该产品已评价!'); $group = UtilService::postMore([ ['comment', ''], ['pics', []], ['product_score', 5], ['service_score', 5] ], Request::instance()); $group['comment'] = htmlspecialchars(trim($group['comment'])); if (sensitive_words_filter($group['comment'])) return JsonService::fail('请注意您的用词,谢谢!!'); if ($group['product_score'] < 1) return JsonService::fail('请为产品评分'); else if ($group['service_score'] < 1) return JsonService::fail('请为商家服务评分'); $group = array_merge($group, [ 'uid' => $uid, 'oid' => $cartInfo['oid'], 'unique' => $unique, 'product_id' => $cartInfo['product_id'], 'reply_type' => 'product' ]); StoreProductReply::beginTrans(); $res = StoreProductReply::reply($group, 'product'); if (!$res) { StoreProductReply::rollbackTrans(); return JsonService::fail('评价失败!'); } try { HookService::listen('store_product_order_reply', $group, $cartInfo, false, StoreProductBehavior::class); } catch (\Exception $e) { StoreProductReply::rollbackTrans(); return JsonService::fail($e->getMessage()); } StoreProductReply::commitTrans(); return JsonService::successful(); } public function get_spread_list($first = 0, $limit = 20) { $list = User::where('spread_uid', $this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->limit($first, $limit)->order('add_time DESC')->select()->toArray(); foreach ($list as $k => $user) { $list[$k]['add_time'] = date('Y/m/d', $user['add_time']); } return JsonService::successful($list); } public function product_reply_list($productId = '', $first = 0, $limit = 8, $filter = 'all') { if (!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!'); $list = StoreProductReply::getProductReplyList($productId, $filter, $first, $limit); return JsonService::successful($list); } public function product_attr_detail($productId = '') { if (!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!'); list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($productId); return JsonService::successful(compact('productAttr', 'productValue')); } public function get_notice_list($page = 0, $limit = 8) { $list = UserNotice::getNoticeList($this->userInfo['uid'], $page, $limit); return JsonService::successful($list); } public function see_notice($nid) { UserNotice::seeNotice($this->userInfo['uid'], $nid); return JsonService::successful(); } public function refresh_msn(Request $request) { $params = $request->post(); $remind_where = "mer_id = " . $params["mer_id"] . " AND uid = " . $params["uid"] . " AND to_uid = " . $params["to_uid"] . " AND type = 0 AND remind = 0"; $remind_list = StoreServiceLog::where($remind_where)->order("add_time asc")->select(); foreach ($remind_list as $key => $value) { if (time() - $value["add_time"] > 3) { StoreServiceLog::edit(array("remind" => 1), $value["id"]); $now_user = StoreService::field("uid,nickname")->where(array("uid" => $params["uid"]))->find(); if (!$now_user) $now_user = User::field("uid,nickname")->where(array("uid" => $params["uid"]))->find(); if ($params["to_uid"]) { $userInfo = WechatUser::where('uid', $params["to_uid"])->field(['openid', 'subscribe'])->find(); if($userInfo && $userInfo['openid'] && $userInfo['subscribe']) { $head = '客服提醒'; $description = '您有新的消息,请注意查收!'; $url = SystemConfigService::get('site_url').'/wap/service/service_ing/to_uid/'.$this->uid.'/mer_id/0'; $message = WechatService::newsMessage($head, $description, $url, $this->userInfo['avatar']); try { WechatService::staffService()->message($message)->to($userInfo['openid'])->send(); } catch (\Exception $e) { \think\Log::error($userInfo['nickname'] . '发送失败' . $e->getMessage()); } } } } } $where = "mer_id = " . $params["mer_id"] . " AND uid = " . $params["to_uid"] . " AND to_uid = " . $params["uid"] . " AND type = 0"; $list = StoreServiceLog::where($where)->order("add_time asc")->select()->toArray(); $ids = []; foreach ($list as $key => $value) { //设置发送人与接收人区别 if ($value["uid"] == $params["uid"]) $list[$key]['my'] = "my"; else $list[$key]['my'] = "to"; array_push($ids, $value["id"]); } //设置这些消息为已读 StoreServiceLog::where(array("id" => array("in", $ids)))->update(array("type" => 1, "remind" => 1)); return JsonService::successful($list); } public function add_msn(Request $request) { $params = $request->post(); if ($params["type"] == "html") $data["msn"] = htmlspecialchars_decode($params["msn"]); else $data["msn"] = $params["msn"]; $data["uid"] = $params["uid"]; $data["to_uid"] = $params["to_uid"]; $data["mer_id"] = $params["mer_id"] > 0 ? $params["mer_id"] : 0; $data["add_time"] = time(); StoreServiceLog::set($data); return JsonService::successful(); } public function get_msn(Request $request) { $params = $request->post(); $size = 10; $page = $params["page"] >= 0 ? $params["page"] : 1; $where = "(mer_id = " . $params["mer_id"] . " AND uid = " . $params["uid"] . " AND to_uid = " . $params["to_uid"] . ") OR (mer_id = " . $params["mer_id"] . " AND uid = " . $params["to_uid"] . " AND to_uid = " . $params["uid"] . ")"; $list = StoreServiceLog::where($where)->limit(($page - 1) * $size, $size)->order("add_time desc")->select()->toArray(); foreach ($list as $key => $value) { //设置发送人与接收人区别 if ($value["uid"] == $params["uid"]) $list[$key]['my'] = "my"; else $list[$key]['my'] = "to"; //设置这些消息为已读 if ($value["uid"] == $params["to_uid"] && $value["to_uid"] == $params["uid"]) StoreServiceLog::edit(array("type" => 1, "remind" => 1), $value["id"]); } $list = array_reverse($list); return JsonService::successful($list); } public function refresh_msn_new(Request $request) { $params = $request->post(); $now_user = User::getUserInfo($this->userInfo['uid']); if ($params["last_time"] > 0) $where = "(uid = " . $now_user["uid"] . " OR to_uid = " . $now_user["uid"] . ") AND add_time>" . $params["last_time"]; else $where = "uid = " . $now_user["uid"] . " OR to_uid = " . $now_user["uid"]; $msn_list = StoreServiceLog::where($where)->order("add_time desc")->select()->toArray(); $info_array = $list = []; foreach ($msn_list as $key => $value) { $to_uid = $value["uid"] == $now_user["uid"] ? $value["to_uid"] : $value["uid"]; if (!in_array(["to_uid" => $to_uid, "mer_id" => $value["mer_id"]], $info_array)) { $info_array[count($info_array)] = ["to_uid" => $to_uid, "mer_id" => $value["mer_id"]]; $to_user = StoreService::field("uid,nickname,avatar")->where(array("uid" => $to_uid))->find(); if (!$to_user) $to_user = User::field("uid,nickname,avatar")->where(array("uid" => $to_uid))->find(); $to_user["mer_id"] = $value["mer_id"]; $to_user["mer_name"] = ''; $value["to_info"] = $to_user; $value["count"] = StoreServiceLog::where(array("mer_id" => $value["mer_id"], "uid" => $to_uid, "to_uid" => $now_user["uid"], "type" => 0))->count(); $list[count($list)] = $value; } } return JsonService::successful($list); } public function get_user_brokerage_list($uid, $first = 0, $limit = 8) { if (!$uid) return $this->failed('用户不存在'); $list = UserBill::field('A.mark,A.add_time,A.number,A.pm')->alias('A')->limit($first, $limit) ->where('A.category', 'now_money')->where('A.type', 'brokerage') ->where('A.uid', $this->userInfo['uid']) ->join('__STORE_ORDER__ B', 'A.link_id = B.id AND B.uid = ' . $uid)->select()->toArray(); return JsonService::successful($list); } public function user_extract() { if (UserExtract::userExtract($this->userInfo, UtilService::postMore([ ['type', '', '', 'extract_type'], 'real_name', 'alipay_code', 'bank_code', 'bank_address', ['price', '', '', 'extract_price'] ]))) return JsonService::successful('申请提现成功!'); else return JsonService::fail(Extract::getErrorInfo()); } public function clear_cache($uni = '') { if ($uni) CacheService::clear(); } /** * 获取今天正在拼团的人的头像和名称 * @return \think\response\Json */ public function get_pink_second_one() { $addTime = mt_rand(time() - 30000, time()); $storePink = StorePink::where('p.add_time', 'GT', $addTime)->alias('p')->where('p.status', 1)->join('User u', 'u.uid=p.uid')->field('u.nickname,u.avatar as src')->find(); return JsonService::successful($storePink); } public function order_details($uni = '') { if (!$uni) return JsonService::fail('参数错误!'); $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni); if (!$order) return JsonService::fail('订单不存在!'); $order = StoreOrder::tidyOrder($order, true); $res = array(); foreach ($order['cartInfo'] as $v) { if ($v['combination_id']) return JsonService::fail('拼团产品不能再来一单,请在拼团产品内自行下单!'); else $res[] = StoreCart::setCart($this->userInfo['uid'], $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0); } $cateId = []; foreach ($res as $v) { if (!$v) return JsonService::fail('再来一单失败,请重新下单!'); $cateId[] = $v['id']; } return JsonService::successful('ok', implode(',', $cateId)); } }