where('enabled',1) ->select(); if(!$res){ return $this->Error('錯誤請求'); } return $this->Success($res); } public function getUserDefaultCvs(){ //從user_cvs取得預設資料 $res=Db::name('user_cvs') ->where('user_id',getIdBySsoId($this->uid)) ->where('is_default',1) ->find(); if(!$res){ return $this->Success('沒有預設的門市',201); } return $this->Success($res); } public function getMyCvs(){ //從user_cvs取得資料 $res=Db::name('user_cvs') ->where('user_id',getIdBySsoId($this->uid)) ->select(); //將$res用foreach的方式以type分類轉成陣列 $default_type = 1; $default_id = ''; $data = []; $default = []; foreach($res as $key => $value){ $data[$value['type']][] = $value; if($value['is_default'] == 1){ $default = $value; } } return $this->Success(['default'=>$default,'data'=>$data]); } public function setDefaultStoreId(){ //更新預設的store_id $store_id = input('post.store_id'); try{ Db::name('user_cvs') ->where('user_id',getIdBySsoId($this->uid)) ->update(['is_default'=>0]); Db::name('user_cvs') ->where('user_id',getIdBySsoId($this->uid)) ->where('store_id',$store_id) ->update(['is_default'=>1]); }catch(\Exception $e){ return $this->Error('請求失敗'); } return $this->Success('請求成功'); } public function process(){ // $data = input('post.'); $data = []; $data=array_merge($data,[ 'sn'=>input('order_sn'), 'amount'=>1000, 'phone'=>'0912345678', 'name'=>'王小明', 'email'=>'wwayne.hsu@gmail.com', 'zip_code'=>'123', ]); $shipping = new ShippingStrategy('ecpay'); $result = $shipping->request($data); // print_r($result); return $this->Success($result['data']); } public function map(){ switch(input('post.type')){ case '1': $logisticsType = 'UNIMARTC2C'; break; case '2': $logisticsType = 'FAMIC2C'; break; case '3': $logisticsType = 'HILIFEC2C'; break; case '4': $logisticsType = 'OKMARTC2C'; break; default: return $this->Error('錯誤請求'); break; } $data = [ 'device'=>'1', 'ExtraData'=>$this->uid, 'LogisticsSubType'=>$logisticsType ]; try{ $shipping = new ShippingStrategy('ecpay'); $result = $shipping->map($data); }catch(\Exception $e){ return $this->Error('請求失敗,請連絡客服人員'); } return $this->Success($result); } public function mapResponse(){ $data = input(); $shipping = new ShippingStrategy('ecpay'); $result = $shipping->mapResponse($data); if(!$result){ return '錯誤請求'; } return redirect($result['redirect_url']); } //刪除使用者的門市 public function deleteLogistic(){ $id = input('id'); try{ Db::name('user_cvs') ->where('id',$id) ->delete(); }catch(\Exception $e){ return $this->Error('請求失敗'); } return $this->Success('請求成功'); } public function response(){ $data = input('post.'); switch(input('shippingcode')){ case 'ecpay': $shipping = new ShippingStrategy('ecpay'); $result = $shipping->response($data); if($result['code']==200){ $order = Db::name('order_info') ->where('order_sn', $result['order_sn']) ->find(); try { //計算分潤 $res = \app\common\Affiliate::calculateProfitShare($order); if($res['code'] == 0){ $result['msg'] .= ',分潤成功'; } //將會員的is_validated欄位改為1 Db::name('users')->where('user_id', $order['user_id'])->update(['is_validated'=>1]); } catch (\Exception $e) { $code = 200; $result['msg'] .= ',分潤失敗'; } } return '1|OK'; break; default: return $this->Error('錯誤請求'); break; } } }