Nav apraksta

OrderController.php 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Apiistrator
  5. * Date: 2018-02-22
  6. * Time: 10:32
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request;
  11. use App\Log;
  12. use App\Admin;
  13. use App\Order;
  14. use App\Oplog;
  15. use App\RedisModel;
  16. use App\Goods;
  17. use App\GoodsSkus;
  18. use App\OrderGoodsSkus;
  19. use App\CustomerInfo;
  20. use App\CustomerConsum;
  21. use Illuminate\Support\Facades\DB;
  22. class OrderController extends Controller {
  23. /**
  24. * 订单列表
  25. */
  26. public function orderList(Request $request){
  27. $admin_id = (int)$request->input('admin_id');
  28. $self_role = DB::table('admin_role')->where('user_id', $admin_id)->pluck('role_name');
  29. $team_id = null;
  30. if($self_role == '管理员'){
  31. $team_id = Admin::where('id', $admin_id)->pluck('team_id');
  32. $admin_id = null;
  33. }
  34. $page = (int)$request->input('page');
  35. $pageSize = 20;
  36. if($page<=0){
  37. $page = 1;
  38. }
  39. $offset = ($page-1) * $pageSize;
  40. $count = Order::where('is_del', 0)->where('warehouse', 3)->where(function($query) use($admin_id, $team_id){
  41. if($admin_id>0) $query->where('admin_id', $admin_id);
  42. if($team_id>0) $query->where('team_id', $team_id);
  43. })->count();
  44. if ($count > 1) {
  45. // 总页数
  46. $pages = ceil($count/$pageSize);
  47. }else{
  48. // 总页数
  49. $pages = 1;
  50. }
  51. $result = Order::select('id', 'status', 'orderCode', 'customerName', 'receiverName', 'receiverMobile', 'receiverState','receiverCity','receiverDistrict','receiverAddress','receivedAmount','buyerMemo','sellerMemo','createTime','admin_id','admin_name','cost', 'logistics_id','is_refund','warehouse','delivery_date','refund_price','refund_type','send_note','freight_cost','payment_type','refuse_reason','refund_note','verify_time','aftersale_fee','aftersale_reason','aftersale_time','refund_time','send_time','should_amount', 'buyer_phone', 'use_coupon', 'use_m_gift', 'use_b_gift')->where('is_del', 0)->where('warehouse', 3)->where(function($query) use($admin_id, $team_id){
  52. if($admin_id>0) $query->where('admin_id', $admin_id);
  53. if($team_id>0) $query->where('team_id', $team_id)->where('status','>',0);
  54. })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  55. $result = json_decode(json_encode($result),true);
  56. $status_arr = array(
  57. 0 => '已录入',
  58. 1 => '待审核',
  59. 2 => '已审核',
  60. 3 => '已发货',
  61. 4 => '已退款'
  62. );
  63. foreach($result as $k=>&$v){
  64. $goods = DB::table('order_goods_skus')->where('order_id', $v['id'])->where('is_del', 0)->orderBy('gift_id', 'asc')->get();
  65. if(!empty($goods)){
  66. foreach($goods as &$item){
  67. $item->goods_name = Goods::where('id', $item->goods_id)->pluck('name');
  68. $item->picUrl = Goods::where('id', $item->goods_id)->pluck('picUrl');
  69. $goods_sku_info = GoodsSkus::select('propsName', 'is_weigh')->where('id', $item->sku_id)->first();
  70. if(!empty($goods_sku_info)){
  71. $item->props_name = $goods_sku_info->propsName;
  72. $item->is_weigh = $goods_sku_info->is_weigh;
  73. }else{
  74. $item->props_name = '';
  75. $item->is_weigh = 0;
  76. }
  77. $item->gift_type = null;
  78. if($item->gift_id>0){
  79. $gift_flag = DB::table('customer_month_gift')->where('id', $item->gift_id)->first();
  80. if($gift_flag->type==1){
  81. $item->gift_type = 1;
  82. }else{
  83. $item->gift_type = 0;
  84. }
  85. }
  86. }
  87. }
  88. $goods = json_decode(json_encode($goods), true);
  89. $v['sku_count'] = count($goods);
  90. $goods = array_slice($goods, 0, 2);
  91. $v['skus'] = $goods;
  92. #加粉时间
  93. $fanTime = DB::table('customers')->select('fanTime')->where('phone', $v['receiverMobile'])->first();
  94. $v['fanTime'] = isset($fanTime->fanTime) ? $fanTime->fanTime : '';
  95. //$v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  96. $v['status_name'] = $status_arr[$v['status']];
  97. // 代金券
  98. if($v['use_coupon'] == 1){
  99. $v['coupon_id'] = DB::table('customer_coupons')->where('order_id', $v['id'])->where('is_use', 1)->pluck('id');
  100. }
  101. }
  102. $pageInfo = [
  103. 'page' => $page,
  104. 'total' => $count,
  105. 'pageSize' => $pageSize,
  106. 'pages' => $pages,
  107. ];
  108. return self::returnValue(['data'=>$result, 'page_info'=>$pageInfo]);
  109. }
  110. /**
  111. * 分组管理-进行添加操作
  112. * @param Request $request
  113. * @return \Illuminate\Http\RedirectResponse
  114. */
  115. public function orderstore(Request $request)
  116. {
  117. $admin_id = (int)$request->input('admin_id');
  118. if(empty($admin_id)){
  119. return self::returnValue(['msg'=>'登录过期'], 2000);
  120. }
  121. $buyer_phone = $request->input('buyer_phone');
  122. if(!preg_match('/^1\d{10}$/', $buyer_phone)){
  123. return self::returnValue(['msg'=>'买家手机号格式有误'], 2000);
  124. }
  125. $phone = $request->input('receiverMobile');
  126. if(!preg_match('/^1\d{10}$/', $phone)){
  127. return self::returnValue(['msg'=>'收货人手机号格式有误'], 2000);
  128. }
  129. $customerName = $request->input('customerName');
  130. if(empty($customerName)){
  131. return self::returnValue(['msg'=>'买家姓名不能为空'], 2000);
  132. }
  133. $receiverName = $request->input('receiverName');
  134. if(empty($receiverName)){
  135. return self::returnValue(['msg'=>'收货人姓名不能为空'], 2000);
  136. }
  137. $receiverState = $request->input('receiverState');
  138. if(empty($receiverState)){
  139. return self::returnValue(['msg'=>'省份不能为空'], 2000);
  140. }
  141. $receiverCity = $request->input('receiverCity');
  142. if(empty($receiverCity)){
  143. return self::returnValue(['msg'=>'市不能为空'], 2000);
  144. }
  145. $receiverAddress = $request->input('receiverAddress');
  146. if(empty($receiverAddress)){
  147. return self::returnValue(['msg'=>'详细地址不能为空'], 2000);
  148. }
  149. $delivery_date = $request->input('delivery_date');
  150. if(empty($delivery_date)){
  151. return self::returnValue(['msg'=>'预发货时间不能为空'], 2000);
  152. }
  153. $receivedAmount = $request->input('receivedAmount');
  154. if(empty($receivedAmount) || !is_numeric($receivedAmount) ){
  155. return self::returnValue(['msg'=>'实付金额不能为空且必须为数字'], 2000);
  156. }
  157. $skus = $request->input('skus');
  158. if(empty($skus)){
  159. return self::returnValue(['msg'=>'必须添加商品'], 2000);
  160. }
  161. $payment_type = (int)$request->input('payment_type');
  162. if(empty($payment_type)){
  163. return self::returnValue(['msg'=>'必选支付方式'], 2000);
  164. }
  165. /*
  166. $redisKey = 'seafood.order_phone_add.'.$phone;
  167. $res = RedisModel::setnx($redisKey, 1);
  168. if( $res == 0 ){
  169. $msg = '操作过于频繁,请一分钟后继续操作';
  170. return self::returnValue(['msg'=>$msg], 2000);
  171. }
  172. $res = RedisModel::expire( $redisKey, 60 );
  173. */
  174. //数据库-新增数据
  175. $order = array();
  176. $order['eshopCode'] = config('constants.ESHOP_CODE'); //默认
  177. $order['outerCode'] = Order::createOuterCode();//随机生成
  178. $order['status'] = (int)$request->input('status');
  179. $order['customerName'] = trim($request->input('customerName')); //买家名称
  180. $order['shippingType'] = '卖家包邮';
  181. $order['expressCompanyCode'] = '10084';
  182. $order['expressCompanyName'] = '顺丰快递';
  183. $order['receiverName'] = trim($request->input('receiverName')); //收件人
  184. $order['receiverMobile'] = trim($request->input('receiverMobile')); //收件人手机
  185. $order['receiverPhone'] = trim($request->input('receiverMobile')); //收件人手机
  186. $order['receiverState'] = trim($request->input('receiverState')); //省份
  187. $order['receiverCity'] = trim($request->input('receiverCity')); //市
  188. $order['receiverDistrict'] = trim($request->input('receiverDistrict')); //市
  189. #省市格式处理
  190. $order['receiverState'] = str_replace(['省', '市'], '', $order['receiverState']);
  191. $order['receiverCity'] = str_replace('市', '', $order['receiverCity']);
  192. $order['receiverDistrict'] = trim($request->input('receiverDistrict')); //区
  193. $order['receiverStreet'] = trim($request->input('receiverStreet')); //街道
  194. $order['receiverAddress'] = trim($request->input('receiverAddress')); //详细地址
  195. $order['buyerPostageFee'] = 0; //买家邮费
  196. $order['discountFee'] = 0; //订单优惠
  197. $order['adjustFee'] = 0; //订单调价
  198. $order['serviceFee'] = 0; //服务费
  199. $order['paymentMethod'] = '在线付款';
  200. $order['paymentType'] = '网银';
  201. $order['paymentAccount'] = '18322225555'; // 付款账号,暂时默认写死
  202. $order['paymentTime'] = date('Y-m-d H:i:s'); // 付款时间
  203. $order['receivedAmount'] = trim($request->input('receivedAmount')); //付款金额
  204. $order['buyerMemo'] = trim($request->input('buyerMemo', '')); // 买家备注
  205. $order['sellerMemo'] = trim($request->input('sellerMemo', '')); // 卖家备注
  206. $order['createTime'] = date('Y-m-d H:i:s'); // 订单创建时间
  207. $order['modifyTime'] = date('Y-m-d H:i:s'); // 订单修改时间
  208. $order['should_amount'] = $request->input('should_amount');
  209. if(!$order['should_amount']) $order['should_amount'] = null;
  210. //商品信息
  211. $skus = $request->input('skus');
  212. $order_goods = array();
  213. if(!empty($skus)){
  214. foreach($skus as $k=>$sku){
  215. $sku_id = $sku['sku_id'];
  216. $num = $sku['num'];
  217. $sku_info = GoodsSkus::where('id', $sku_id)->first();
  218. $goods_info = Goods::where('id', $sku_info->goodsCode)->first();
  219. $params = array();
  220. $params['outerCode'] = $order['outerCode']+$k+1; //外部平台中子订单编码
  221. $params['outerParentCode'] = $order['outerCode']; //外部平台中订单编码
  222. $params['goodsCode'] = $sku_info->goodsCode;// strstr($goods->code,'-',true);
  223. $params['skuCode'] = $sku_id;
  224. #商品名称
  225. $params['goodsName'] = $goods_info->name;
  226. $params['propertiesName'] = $sku_info->propsName;
  227. $params['price'] = $sku_info->price;
  228. $params['quantity'] = $num;
  229. $params['discountFee'] = 0;
  230. $params['adjustFee'] = 0;
  231. $params['refundStatus'] = '正常';
  232. $order_goods[] = $params;
  233. }
  234. }
  235. //本系统订单额外参数
  236. $order['warehouse'] = 3; //仓库
  237. $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期
  238. $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
  239. $order['buyer_phone'] = $request->input('buyer_phone');
  240. $coupon_id = (int)$request->input('coupon_id');
  241. if($coupon_id>0){
  242. if($order['payment_type'] == 4){
  243. return self::returnValue(['msg'=>'优惠券和充值卡不能同时使用'], 2000);
  244. }
  245. $order['use_coupon'] = 1;
  246. }
  247. $order['use_b_gift'] = (int)$request->input('use_b_gift');
  248. $m_gift_id = (int)$request->input('m_gift_id');
  249. if($m_gift_id>0){
  250. $order['use_m_gift'] = 1;
  251. }
  252. //充值卡验证余额
  253. if($order['payment_type'] == 4){
  254. $deposit_phone = $request->input('deposit_phone');
  255. $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
  256. $balance = isset($customerInfo->balance) ? $customerInfo->balance : 0;
  257. if($balance < $order['receivedAmount']){
  258. $msg = '余额不足';
  259. return self::returnValue(['msg'=>$msg], 2003);
  260. }
  261. }
  262. $admin_id = (int)$request->input('admin_id');
  263. DB::beginTransaction();
  264. try{
  265. #更新客户表
  266. $customer = array();
  267. $customers['name'] = $order['receiverName'];
  268. $customers['receiverState'] = $order['receiverState'];
  269. $customers['receiverCity'] = $order['receiverCity'];
  270. $customers['receiverDistrict'] = $order['receiverDistrict'];
  271. $customers['receiverStreet'] = $order['receiverStreet'];
  272. $customers['receiverAddress'] = $order['receiverAddress'];
  273. $customers['buyerMobile'] = $order['buyer_phone'];
  274. $customers['buyerName'] = $order['customerName'];
  275. $if_e = DB::table('customers')->select('id', 'fanTime')->where('phone', $order['receiverMobile'])->first();
  276. if(isset($if_e->id)){
  277. $customers['is_fugou'] = 1;
  278. $order['is_fugou'] = 1;
  279. $up_c = DB::table('customers')->where('id', $if_e->id)->update($customers);
  280. }else{
  281. $customers['phone'] = $order['receiverMobile'];
  282. $customers['is_fugou'] = 0;
  283. $customers['fanTime'] = $request->input('fanTime');
  284. $customers['admin_id'] = $admin_id;
  285. $in_c = DB::table('customers')->insert($customers);
  286. }
  287. $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
  288. $order['admin_id'] = $admin_id;
  289. $order['admin_name'] = $admin_info->realname;
  290. $order['team_id'] = $admin_info->team_id;
  291. //新加is_able 9.4之前粉丝不参与销售复购统计
  292. $fanTime = $request->input('fanTime');
  293. if(!$fanTime && isset($if_e->id)) $fanTime = $if_e->fanTime;
  294. if($fanTime < '2019-09-04'){
  295. $order['is_able'] = 0;
  296. }
  297. $res = DB::table('order')->insertGetId($order);
  298. if($res){
  299. if(!empty($skus)){
  300. //订单商品插入
  301. $order_skus = array();
  302. foreach($order_goods as $k=>$sku){
  303. $order_skus[$k]['sku_id'] = $sku['skuCode'];
  304. $order_skus[$k]['order_id'] = $res;
  305. $order_skus[$k]['goods_id'] = $sku['goodsCode'];
  306. $order_skus[$k]['num'] = $sku['quantity'];
  307. $order_skus[$k]['price'] = $sku['price'];
  308. }
  309. $order_skus_insert = DB::table('order_goods_skus')->insert($order_skus);
  310. }
  311. #加赠品逻辑
  312. $use_b_gift = (int)$request->input('use_b_gift');
  313. if($coupon_id > 0){
  314. $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('id', $coupon_id)->where('is_use',0)->first();
  315. if(!empty($coupon)){
  316. $cup = array();
  317. $cup['is_use'] = 1;
  318. $cup['use_time'] = date('Y-m-d H:i:s');
  319. $cup['order_id'] = $res;
  320. DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
  321. }
  322. }
  323. if($m_gift_id>0){
  324. $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
  325. $order_m_gift = array();
  326. $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
  327. $order_m_gift['sku_id'] = $m_gift->sku_id;
  328. $order_m_gift['order_id'] = $res;
  329. $order_m_gift['goods_id'] = $m_sku->goodsCode;
  330. $order_m_gift['num'] = $m_gift->num;
  331. $order_m_gift['price'] = $m_sku->price;
  332. $order_m_gift['gift_id'] = $m_gift_id;
  333. $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
  334. #记录领取
  335. $receive_gift = array();
  336. $receive_gift['phone'] = $order['buyer_phone'];
  337. $receive_gift['dtime'] = date('Y-m-d');
  338. $receive_gift['order_id'] = $res;
  339. $receive_gift['gift_id'] = $m_gift_id;
  340. $receive_gift['gift_type'] = 0;
  341. DB::table('customer_gift_receives')->insert($receive_gift);
  342. }
  343. $mdate = date('Y-m-01');
  344. if($use_b_gift>0){
  345. $b_gifts = DB::table('customer_month_gift')->where('mtime', $mdate)->where('type', 1)->get();
  346. $b_gifts = json_decode(json_encode($b_gifts),true);
  347. foreach($b_gifts as $b_gift){
  348. $order_b_gift = array();
  349. $b_sku = GoodsSkus::where('id', $b_gift['sku_id'])->first();
  350. $order_b_gift['sku_id'] = $b_gift['sku_id'];
  351. $order_b_gift['order_id'] = $res;
  352. $order_b_gift['goods_id'] = $b_sku->goodsCode;
  353. $order_b_gift['num'] = $b_gift['num'];
  354. $order_b_gift['price'] = $b_sku->price;
  355. $order_b_gift['gift_id'] = $b_gift['id'];
  356. $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
  357. }
  358. #记录领取
  359. $receive_gift = array();
  360. $receive_gift['phone'] = $order['buyer_phone'];
  361. $receive_gift['dtime'] = date('Y-m-d');
  362. $receive_gift['order_id'] = $res;
  363. $receive_gift['gift_type'] = 1;
  364. DB::table('customer_gift_receives')->insert($receive_gift);
  365. }
  366. #新加逻辑,若付款方式为充值卡/消费记录
  367. if($order['payment_type'] == 4){
  368. $consum = new CustomerConsum();
  369. $consum->phone = $deposit_phone;
  370. $consum->order_id = $res;
  371. $consum->money = $order['receivedAmount'];
  372. $consum->save();
  373. //更新余额
  374. $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
  375. $customerInfo->save();
  376. }
  377. #记录操作日志
  378. $self_id = $admin_id;
  379. $self_name = $admin_info->realname;
  380. if($order['status'] == 0){
  381. $status_text = '仅录入';
  382. }else{
  383. $status_text = '录入并提审';
  384. }
  385. $context = "录入订单:".$status_text;
  386. $type = 0; //订单录入
  387. $tables = 'order';
  388. $data_id = $res;
  389. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  390. }
  391. DB::commit();
  392. }catch (Exception $e){
  393. DB::rollback();
  394. }
  395. return self::returnValue(['msg'=>'添加成功']);
  396. }
  397. /**
  398. * 根据手机号获取默认地址信息
  399. *
  400. */
  401. public function getAddress(Request $request){
  402. $phone = $request->input('phone');
  403. if(!preg_match('/^1\d{10}$/', $phone)){
  404. return self::returnValue([],2000);
  405. }
  406. $result = DB::table('customers')->select('name', 'receiverState', 'receiverCity', 'receiverDistrict', 'receiverAddress', 'fanTime', 'buyerMobile', 'buyerName')->where('phone', $phone)->first();
  407. $result = json_decode(json_encode($result), true);
  408. return self::returnValue(['data'=>$result]);
  409. }
  410. //获余额
  411. public function getBalance(Request $request){
  412. $phone = $request->input('phone');
  413. if(!preg_match('/^1\d{10}$/', $phone)){
  414. return self::returnValue([],2000);
  415. }
  416. $result = CustomerInfo::where('phone', $phone)->pluck('balance');
  417. if(empty($result)) $result = 0;
  418. return self::returnValue(['balance'=>$result]);
  419. }
  420. /**
  421. * 分组管理-进行编辑操作
  422. * @param Request $request
  423. * @return \Illuminate\Http\RedirectResponse
  424. */
  425. public function orderupdate(Request $request)
  426. {
  427. $admin_id = (int)$request->input('admin_id');
  428. if(empty($admin_id)){
  429. return self::returnValue(['msg'=>'登录过期'], 2000);
  430. }
  431. $id = (int)$request->input('id');
  432. if(empty($id)){
  433. return self::returnValue(['msg'=>'订单id有误'], 2000);
  434. }
  435. $phone = $request->input('receiverMobile');
  436. if(!preg_match('/^1\d{10}$/', $phone)){
  437. return self::returnValue(['msg'=>'手机号格式有误'], 2000);
  438. }
  439. $customerName = $request->input('customerName');
  440. if(empty($customerName)){
  441. return self::returnValue(['msg'=>'买家姓名不能为空'], 2000);
  442. }
  443. $receiverName = $request->input('receiverName');
  444. if(empty($receiverName)){
  445. return self::returnValue(['msg'=>'收货人姓名不能为空'], 2000);
  446. }
  447. $receiverState = $request->input('receiverState');
  448. if(empty($receiverState)){
  449. return self::returnValue(['msg'=>'省份不能为空'], 2000);
  450. }
  451. $receiverCity = $request->input('receiverCity');
  452. if(empty($receiverCity)){
  453. return self::returnValue(['msg'=>'市不能为空'], 2000);
  454. }
  455. $receiverAddress = $request->input('receiverAddress');
  456. if(empty($receiverAddress)){
  457. return self::returnValue(['msg'=>'详细地址不能为空'], 2000);
  458. }
  459. $delivery_date = $request->input('delivery_date');
  460. if(empty($delivery_date)){
  461. return self::returnValue(['msg'=>'预发货时间不能为空'], 2000);
  462. }
  463. $receivedAmount = $request->input('receivedAmount');
  464. if(empty($receivedAmount) || !is_numeric($receivedAmount) ){
  465. return self::returnValue(['msg'=>'实付金额不能为空且必须为数字'], 2000);
  466. }
  467. $skus = $request->input('skus');
  468. if(empty($skus)){
  469. return self::returnValue(['msg'=>'必须添加商品'], 2000);
  470. }
  471. $payment_type = (int)$request->input('payment_type');
  472. if(empty($payment_type)){
  473. return self::returnValue(['msg'=>'必选支付方式'], 2000);
  474. }
  475. //更新数据
  476. $order = array();
  477. $order['customerName'] = trim($request->input('customerName')); //买家名称
  478. $order['receiverName'] = trim($request->input('receiverName')); //收件人
  479. if(preg_match('/^1\d{10}$/', $phone)) $order['receiverMobile'] = $phone; //收件人手机
  480. $order['receiverState'] = trim($request->input('receiverState')); //省份
  481. $order['receiverCity'] = trim($request->input('receiverCity')); //市
  482. $order['receiverState'] = str_replace(['省', '市'], '', $order['receiverState']);
  483. $order['receiverCity'] = str_replace('市', '', $order['receiverCity']);
  484. $order['receiverDistrict'] = trim($request->input('receiverDistrict')); //区
  485. $order['receiverAddress'] = trim($request->input('receiverAddress')); //详细地址
  486. $order['receivedAmount'] = trim($request->input('receivedAmount')); //付款金额
  487. $order['buyerMemo'] = trim($request->input('buyerMemo', '')); // 买家备注
  488. $order['sellerMemo'] = trim($request->input('sellerMemo', '')); // 卖家备注
  489. $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期
  490. $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
  491. $order['use_coupon'] = 0;
  492. $coupon_id = (int)$request->input('coupon_id');
  493. if($coupon_id>0){
  494. if($order['payment_type'] == 4){
  495. return self::returnValue(['msg'=>'充值卡不能和优惠券同时使用'], 2000);
  496. }
  497. $order['use_coupon'] = 1;
  498. }
  499. $order['buyer_phone'] = $request->input('buyer_phone');
  500. $order['use_b_gift'] = (int)$request->input('use_b_gift');
  501. $m_gift_id = (int)$request->input('m_gift_id');
  502. if($m_gift_id>0){
  503. $order['use_m_gift'] = 1;
  504. }
  505. $order['status'] = (int)$request->input('status');
  506. $order['should_amount'] = $request->input('should_amount');
  507. if(!$order['should_amount']) $order['should_amount'] = null;
  508. $id = (int)$request->input('id');
  509. //获取订单原信息
  510. $old_order = DB::table('order')->where('id', $id)->first();
  511. // ++++++充值卡验证余额逻辑 +++++++ //
  512. if($order['payment_type'] == 4){
  513. if($old_order->payment_type != 4){
  514. $deposit_phone = $request->input('deposit_phone');
  515. $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
  516. $balance = isset($customerInfo->balance) ? $customerInfo->balance : 0 ;
  517. if($balance < $order['receivedAmount']){
  518. //余额不足
  519. return self::returnValue(['msg'=>'充值卡余额不足'], 2003);
  520. }
  521. }elseif($old_order->receivedAmount != $order['receivedAmount']){
  522. $deposit_phone = CustomerConsum::where('order_id', $id)->where('is_del', 0)->where('type', 0)->pluck('phone');
  523. $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
  524. $balance = $customerInfo->balance;
  525. if( $balance < $order['receivedAmount']-$old_order->receivedAmount ){
  526. //余额不足
  527. return self::returnValue(['msg'=>'充值卡余额不足'], 2003);
  528. }
  529. }
  530. }
  531. $today_date = date('Y-m-d');
  532. DB::beginTransaction();
  533. try{
  534. $res = DB::table('order')->where('id', $id)->update($order);
  535. //商品信息
  536. $skus = $request->input('skus');
  537. $sku_ids = array_column($skus, 'sku_id');
  538. //先删除
  539. $del_re = DB::table('order_goods_skus')->where('order_id', $id)->whereNull('gift_id')->whereNotIn('sku_id', $sku_ids)->update(['is_del'=>1]);
  540. if(!empty($skus)){
  541. //再同步
  542. foreach($skus as $k=>$sku){
  543. $sku_id = $sku['sku_id'];
  544. $num = $sku['num'];
  545. $sku_info = GoodsSkus::select('goodsCode', 'price', 'propsName','is_weigh')->where('id', $sku_id)->first();
  546. $sync_re = OrderGoodsSkus::updateOrCreate(['order_id'=>$id, 'sku_id'=>$sku_id, 'goods_id'=>$sku_info->goodsCode], ['num'=>$num, 'is_del'=>0, 'price'=>$sku_info->price]);
  547. }
  548. }
  549. if($res){
  550. #新加逻辑,若付款方式为充值卡/消费记录
  551. if($order['payment_type'] == 4 ){
  552. if($old_order->payment_type != 4 ){
  553. $consum = new CustomerConsum();
  554. $consum->phone = $deposit_phone;
  555. $consum->order_id = $id;
  556. $consum->money = $order['receivedAmount'];
  557. $consum->save();
  558. //更新余额
  559. $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
  560. $customerInfo->save();
  561. }elseif($old_order->receivedAmount != $order['receivedAmount']){
  562. $consum = CustomerConsum::where('order_id', $id)->first();
  563. $consum->money = $order['receivedAmount'];
  564. $consum->save();
  565. //更新余额
  566. $add_amount = $order['receivedAmount'] - $old_order->receivedAmount; //新增消费额,有可能为负数
  567. $customerInfo->balance = $customerInfo->balance - $add_amount;
  568. $customerInfo->save();
  569. }
  570. }
  571. #记录操作日志
  572. $self_id = (int)$request->input('admin_id');
  573. $self_name = Admin::where('id', $self_id)->pluck('realname');
  574. $context = "修改订单";
  575. $type = 0;
  576. $tables = 'order';
  577. $data_id = $id;
  578. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  579. }
  580. #新加逻辑,使用优惠券,赠礼
  581. $use_b_gift = (int)$request->input('use_b_gift');
  582. if($coupon_id > 0 && $old_order->use_coupon != 1){
  583. $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('id', $coupon_id)->where('is_use',0)->orderBy('id', 'desc')->first();
  584. if(!empty($coupon)){
  585. $cup = array();
  586. $cup['is_use'] = 1;
  587. $cup['use_time'] = date('Y-m-d H:i:s');
  588. $cup['order_id'] = $id;
  589. DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
  590. }
  591. }elseif($coupon_id == 0 && $old_order->use_coupon == 1){
  592. DB::table('customer_coupons')->where('order_id', $id)->update(['is_use'=>0]);
  593. }elseif($coupon_id > 0 && $old_order->use_coupon == 1){
  594. $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('id', $coupon_id)->first();
  595. if(!empty($coupon) && $coupon->is_use == 0){
  596. DB::table('customer_coupons')->where('order_id', $id)->update(['is_use'=>0]);
  597. $cup = array();
  598. $cup['is_use'] = 1;
  599. $cup['use_time'] = date('Y-m-d H:i:s');
  600. $cup['order_id'] = $id;
  601. DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
  602. }
  603. }
  604. #查询本单使用赠礼
  605. $order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
  606. $order_m_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 0)->pluck('id');
  607. $order_b_gift_ids = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->lists('id');
  608. if($m_gift_id>0 && empty($order_m_gift_id) ){
  609. $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
  610. $order_m_gift = array();
  611. $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
  612. $order_m_gift['sku_id'] = $m_gift->sku_id;
  613. $order_m_gift['order_id'] = $id;
  614. $order_m_gift['goods_id'] = $m_sku->goodsCode;
  615. $order_m_gift['num'] = $m_gift->num;
  616. $order_m_gift['price'] = $m_sku->price;
  617. $order_m_gift['gift_id'] = $m_gift_id;
  618. $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
  619. #记录领取
  620. $receive_gift = array();
  621. $receive_gift['phone'] = $order['buyer_phone'];
  622. $receive_gift['dtime'] = date('Y-m-d');
  623. $receive_gift['order_id'] = $id;
  624. $receive_gift['gift_id'] = $m_gift_id;
  625. $receive_gift['gift_type'] = 0;
  626. DB::table('customer_gift_receives')->insert($receive_gift);
  627. }elseif($m_gift_id>0 && $m_gift_id != $order_m_gift_id){
  628. DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
  629. DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
  630. $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
  631. $order_m_gift = array();
  632. $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
  633. $order_m_gift['sku_id'] = $m_gift->sku_id;
  634. $order_m_gift['order_id'] = $id;
  635. $order_m_gift['goods_id'] = $m_sku->goodsCode;
  636. $order_m_gift['num'] = $m_gift->num;
  637. $order_m_gift['price'] = $m_sku->price;
  638. $order_m_gift['gift_id'] = $m_gift_id;
  639. $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
  640. #记录领取
  641. $receive_gift = array();
  642. $receive_gift['phone'] = $order['buyer_phone'];
  643. $receive_gift['dtime'] = date('Y-m-d');
  644. $receive_gift['order_id'] = $id;
  645. $receive_gift['gift_id'] = $m_gift_id;
  646. $receive_gift['gift_type'] = 0;
  647. DB::table('customer_gift_receives')->insert($receive_gift);
  648. }elseif($m_gift_id==0 && $order_m_gift_id>0){
  649. DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
  650. DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
  651. }
  652. $mdate = date('Y-m-01', strtotime($old_order->create_time));
  653. if($use_b_gift>0 && empty($order_b_gift_ids) ){
  654. $b_gifts = DB::table('customer_month_gift')->where('mtime', $mdate)->where('type', 1)->get();
  655. $b_gifts = json_decode(json_encode($b_gifts),true);
  656. foreach($b_gifts as $b_gift){
  657. $order_b_gift = array();
  658. $b_sku = GoodsSkus::where('id', $b_gift['sku_id'])->first();
  659. $order_b_gift['sku_id'] = $b_gift['sku_id'];
  660. $order_b_gift['order_id'] = $id;
  661. $order_b_gift['goods_id'] = $b_sku->goodsCode;
  662. $order_b_gift['num'] = $b_gift['num'];
  663. $order_b_gift['price'] = $b_sku->price;
  664. $order_b_gift['gift_id'] = $b_gift['id'];
  665. $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
  666. }
  667. #记录领取
  668. $receive_gift = array();
  669. $receive_gift['phone'] = $order['buyer_phone'];
  670. $receive_gift['dtime'] = date('Y-m-d');
  671. $receive_gift['order_id'] = $id;
  672. $receive_gift['gift_type'] = 1;
  673. DB::table('customer_gift_receives')->insert($receive_gift);
  674. }elseif($use_b_gift==0 && !empty($order_b_gift_ids)){
  675. DB::table('order_goods_skus')->whereIn('gift_id', $order_b_gift_ids)->where('order_id', $id)->update(['is_del'=>1]);
  676. DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_type', 1)->update(['is_del'=>1]);
  677. }
  678. DB::commit();
  679. }catch (Exception $e){
  680. DB::rollback();
  681. Log::errorLog($request,['error'=>$e->getMessage()],"order/update",0,'');
  682. return self::returnValue(['msg'=>$e->getMessage()], 2000);
  683. }
  684. return self::returnValue(['msg' => '更新成功']);
  685. }
  686. /**
  687. * 订单审核
  688. */
  689. public function setverify(Request $request){
  690. $id = (int)$request->input('id');
  691. $order = Order::find($id);
  692. $old_status = $order->status;
  693. $order->status = (int)$request->input('status');
  694. if($order->status == 0){
  695. $refuse_reason = trim($request->input('refuse_reason'));
  696. if(!empty($refuse_reason)){
  697. $order->refuse_reason = $refuse_reason;
  698. }
  699. }
  700. if($order->status == 2 || $order->status == 0){
  701. $order->verify_time = date('Y-m-d H:i:s'); //审核时间
  702. }
  703. //获取可变更状态
  704. $enableStatus = $this->getEnableStatus($old_status);
  705. if( !empty($enableStatus) ){
  706. $statusArr = array_column($enableStatus, 'status');
  707. if( !in_array($order->status, $statusArr) ){
  708. return self::returnValue(['msg'=>'异常操作'], 2000);
  709. }
  710. }else{
  711. return self::returnValue(['msg'=>'异常操作'], 2000);
  712. }
  713. DB::beginTransaction();
  714. try{
  715. $res = $order ->save();
  716. if($res){
  717. #记录操作日志
  718. $status_arr = array(
  719. 0 => '已录入',
  720. 1 => '待审核',
  721. 2 => '已审核',
  722. 3 => '已发货',
  723. 4 => '已退款'
  724. );
  725. $self_id = (int)$request->input('admin_id');
  726. $self_name = Admin::where('id', $self_id)->pluck('realname');
  727. $context = "订单状态变更:【".$status_arr[$old_status]."】变更为【". $status_arr[$order->status]."】({$old_status}->{$order->status})";
  728. $type = 1; //状态变更
  729. $tables = 'order';
  730. $data_id = $id;
  731. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  732. $today_date = date('Y-m-d');
  733. #如果审核通过,c仓, 并且到预发货时间,同步卖家云
  734. if($order->status == 2 && $order->warehouse == 3 && $order->delivery_date <= $today_date){
  735. $syncMj = $this->syncOrderToMj($id);
  736. if( $syncMj == false ){
  737. throw new Exception("订单同步到卖家云失败");
  738. }
  739. }
  740. }
  741. DB::commit();
  742. }catch (Exception $e){
  743. Log::errorLog($request,['error'=>$e->getMessage()],"order/setverify",0,['id'=>$id]);
  744. DB::rollback();
  745. return self::returnValue(['msg'=>$e->getMessage()], 2000);
  746. }
  747. return self::returnValue(['msg'=>'操作成功']);
  748. }
  749. /**
  750. * 订单状态机制,获取可变更状态
  751. * @param status:0已录入 1提交审核 2已审核 3已发货 4已退款
  752. */
  753. public function getEnableStatus($status){
  754. $status_arr = [
  755. 0 => ['status'=>0, 'name'=>'已录入'],
  756. 1 => ['status'=>1, 'name'=>'提交审核'],
  757. 2 => ['status'=>2, 'name'=>'审核通过'],
  758. 3 => ['status'=>3, 'name'=>'设为发货'],
  759. 4 => ['status'=>4, 'name'=>'设为退款']
  760. ];
  761. $status = (int)$status;
  762. $result = array();
  763. switch ($status) {
  764. case '0':
  765. $result[] = $status_arr[1];
  766. break;
  767. case '1':
  768. $result[] = $status_arr[2];
  769. $result[] = $status_arr[0];
  770. break;
  771. case '2':
  772. $result[] = $status_arr[1];
  773. $result[] = $status_arr[3];
  774. break;
  775. default:
  776. break;
  777. }
  778. return $result;
  779. }
  780. /**
  781. * 订单同步到卖家云
  782. */
  783. public function syncOrderToMj($id, $order = []){
  784. if( empty($order) ){
  785. $order = Order::select('eshopCode','outerCode','status','customerName','shippingType','expressCompanyCode','expressCompanyName','receiverName','receiverMobile','receiverPhone','receiverState','receiverCity','receiverDistrict','receiverStreet','receiverAddress','buyerPostageFee','discountFee','adjustFee','serviceFee','paymentMethod','paymentType','paymentAccount','paymentTime','receivedAmount','buyerMemo','sellerMemo','createTime','modifyTime')->where('id', $id)->first();
  786. $order = json_decode(json_encode($order), true);
  787. $skus = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->get();
  788. $skus = json_decode(json_encode($skus), true);
  789. foreach($skus as $k=>$v){
  790. $sku_info = GoodsSkus::where('id', $v['sku_id'])->first();
  791. $goods_info = Goods::where('id', $v['goods_id'])->first();
  792. $params = array();
  793. $params['outerCode'] = $order['outerCode']+$k+1; //外部平台中子订单编码
  794. $params['outerParentCode'] = $order['outerCode']; //外部平台中订单编码
  795. $params['goodsCode'] = $sku_info->goodsCode;//
  796. $params['skuCode'] = $v['sku_id'];
  797. #商品名称
  798. $params['goodsName'] = $goods_info->name;
  799. $params['propertiesName'] = $sku_info->is_weigh==1 ? $sku_info->propsName.'【按半斤称重】' : $sku_info->propsName;
  800. //$params['goodsName'] = '海钓黄翅鱼';//$goods->code;
  801. $params['price'] = $sku_info->is_weigh==1 ? round($v['price']/2,2) : $v['price'];
  802. $params['quantity'] = (int)($sku_info->is_weigh==1 ? $v['num']*2 : $v['num']);
  803. $params['discountFee'] = 0;
  804. $params['adjustFee'] = 0;
  805. $params['refundStatus'] = '正常';
  806. $order['skuList'][] = $params;
  807. }
  808. }
  809. //卖家云添加订单 ->改为审核通过再同步卖家云
  810. $mj_add = Order::mjOrderAdd($order);
  811. //同步卖家云订单数据到本系统
  812. if( isset($mj_add['order']['code']) ){
  813. $mjorder = array();
  814. $mjorder['orderCode'] = $mj_add['order']['code'];
  815. Order::where('id', $id)->update($mjorder);
  816. }
  817. return $mj_add;
  818. }
  819. /**
  820. * 订单详情
  821. */
  822. public function orderDetail(Request $request){
  823. $admin_id = (int)$request->input('admin_id');
  824. $id = (int)$request->input('id');
  825. $self_role = DB::table('admin_role')->where('user_id', $admin_id)->pluck('role_name');
  826. $team_id = null;
  827. if($self_role == '管理员'){
  828. $team_id = Admin::where('id', $admin_id)->pluck('team_id');
  829. $admin_id = null;
  830. }
  831. $order = Order::select('id', 'status', 'orderCode', 'customerName', 'receiverName', 'receiverMobile', 'receiverState','receiverCity','receiverDistrict','receiverAddress','receivedAmount','buyerMemo','sellerMemo','createTime','admin_id','admin_name','cost', 'logistics_id','is_refund','warehouse','delivery_date','refund_price','refund_type','send_note','freight_cost','payment_type','refuse_reason','refund_note','verify_time','aftersale_fee','aftersale_reason','aftersale_time','refund_time','send_time','should_amount', 'buyer_phone', 'use_coupon', 'use_m_gift', 'use_b_gift')->where('is_del', 0)->where('warehouse', 3)->where('id', $id)->first();
  832. $status_arr = array(
  833. 0 => '已录入',
  834. 1 => '待审核',
  835. 2 => '已审核',
  836. 3 => '已发货',
  837. 4 => '已退款'
  838. );
  839. $goods = OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->get();
  840. $skus = array();
  841. $m_gifts = array();
  842. $b_gifts = array();
  843. if(!empty($goods)){
  844. foreach($goods as &$item){
  845. $item->goods_name = Goods::where('id', $item->goods_id)->pluck('name');
  846. $item->picUrl = Goods::where('id', $item->goods_id)->pluck('picUrl');
  847. $goods_sku_info = GoodsSkus::select('propsName', 'is_weigh')->where('id', $item->sku_id)->first();
  848. if(!empty($goods_sku_info)){
  849. $item->props_name = $goods_sku_info->propsName;
  850. $item->is_weigh = $goods_sku_info->is_weigh;
  851. }else{
  852. $item->props_name = '';
  853. $item->is_weigh = 0;
  854. }
  855. $item->gift_type = null;
  856. if($item->gift_id>0){
  857. $gift_flag = DB::table('customer_month_gift')->where('id', $item->gift_id)->first();
  858. if($gift_flag->type==1){
  859. $item->gift_type = 1;
  860. $b_gifts[] = $item;
  861. }else{
  862. $item->gift_type = 0;
  863. $m_gifts[] = $item;
  864. }
  865. }else{
  866. $skus[] = $item;
  867. }
  868. }
  869. }
  870. $order->skus = $skus;
  871. $order->m_gifts = $m_gifts;
  872. $order->b_gifts = $b_gifts;
  873. #加粉时间
  874. $fanTime = DB::table('customers')->select('fanTime')->where('phone', $order->receiverMobile)->first();
  875. $order->fanTime = isset($fanTime->fanTime) ? $fanTime->fanTime : '';
  876. //$v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  877. $order->status_name = $status_arr[$order->status];
  878. // 代金券
  879. $order->coupon_price = null;
  880. if($order->use_coupon == 1){
  881. $coupon_info = DB::table('customer_coupons')->where('order_id', $id)->where('is_use', 1)->first();
  882. $order->coupon_id = $coupon_info->id;
  883. $order->coupon_price = $coupon_info->coupon_price;
  884. }
  885. #查询用户会员信息
  886. $cust_info = array();
  887. $cust_info['if_coupons'] = 0;
  888. $cust_info['if_m_gift'] = 0;
  889. $cust_info['if_b_gift'] = 0;
  890. $order->is_vip = 0;
  891. $phone = $order->buyer_phone;
  892. $time = date('Y-m-d H:i:s');
  893. $mtime = date('Y-m-01');
  894. $customer_info = DB::table('customer_vip')->where('phone', $phone)->where('is_del', 0)->first();
  895. if( !empty($customer_info) ){
  896. //判断是否过期
  897. if($customer_info->vip_end_time > $time){
  898. $order->is_vip = 1;
  899. $coupons = DB::table('customer_coupons')->where('phone', $phone)->where('is_use', 0)->where('end_time', '>', $time)->first();
  900. $cust_info['if_coupons'] = !empty($coupons) ? 1:0;
  901. if($order['createTime'] >= $mtime){
  902. //未过期,1.获取优惠券,获取当月礼,获取生日礼,判断领取
  903. //判断是否领取当月礼
  904. $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
  905. if(empty($if_m_gift)){
  906. $cust_info['if_m_gift'] = 1;
  907. }
  908. //判断生日礼
  909. $birth_time = date('m', strtotime($customer_info->birthday));
  910. $tom = date('m');
  911. if($tom==$birth_time){
  912. //生日期内,判断是否已领
  913. $if_b_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first();
  914. if(empty($if_b_gift)){
  915. $cust_info['if_b_gift'] = 1;
  916. }
  917. }
  918. }
  919. }
  920. }
  921. //额外+判断 ,若已领,则可领
  922. if($order->use_coupon == 1){
  923. $cust_info['if_coupons'] = 1;
  924. }
  925. if($order->use_m_gift == 1){
  926. $cust_info['if_m_gift'] = 1;
  927. }
  928. if($order->use_b_gift == 1){
  929. $cust_info['if_b_gift'] = 1;
  930. }
  931. $order->if_coupons = $cust_info['if_coupons'];
  932. $order->if_m_gift = $cust_info['if_m_gift'];
  933. $order->if_b_gift = $cust_info['if_b_gift'];
  934. return self::returnValue(['data'=>$order]);
  935. }
  936. }