<?php
|
|
namespace app\api\controller\takeout;
|
|
use app\api\controller\Controller;
|
use app\common\library\easywechat\AppMp;
|
use app\api\model\store\Store as StoreModel;
|
use app\common\model\store\Order as StoreOrderModel;
|
use app\api\model\store\Clerk as ClerkModel;
|
use app\supplier\model\store\Clerk as supplierClerkModel;
|
use app\api\model\order\Order as OrderModel;
|
use app\api\model\supplier\Supplier as SupplierModel;
|
use app\api\service\pay\PayService;
|
use app\common\model\store\Clerkcash as CashModel;
|
use app\common\exception\BaseException;
|
use app\api\model\settings\Message as MessageModel; // by lyzflash
|
use app\api\model\user\UserAuth;
|
|
use app\common\model\takeout\Commander as CommanderModel;
|
use app\api\model\takeout\Deliveryman as DeliverymanModel;
|
|
/**
|
* 门店列表
|
*/
|
class Deliveryman extends Controller
|
{
|
private $user;
|
private $deliveryman; // 配送员
|
|
/**
|
* 构造方法
|
*/
|
public function initialize()
|
{
|
parent::initialize();
|
$this->user = $this->getUser(); // 用户信息
|
$deliveryman = DeliverymanModel::detail($this->user['user_id']);
|
if (empty($deliveryman)) {
|
throw new BaseException(['msg' => '您还不是配送员']);
|
}
|
$this->deliveryman = $deliveryman;
|
}
|
|
/**
|
* 门店详情
|
*/
|
public function detail()
|
{
|
$user = $this->getUser();
|
$detail =ClerkModel::detail(['user_id'=>$user['user_id']]);
|
if (empty($detail)) {
|
return $this->renderError('您还不是配送员');
|
}
|
$store_id=$detail['store_id'];
|
$store = StoreModel::detail($store_id);
|
$settlement = $this->getSet();
|
$payType=$settlement['pay_type'];
|
return $this->renderSuccess('', compact('detail','payType','store'));
|
}
|
//成交数据
|
public function tradeData($url = '', $platform= '')
|
{
|
$data = $this->postData();
|
$user = $this->getUser();
|
|
$detail =ClerkModel::detail(['user_id'=>$user['user_id']]);
|
if (empty($detail)) {
|
return $this->renderError('您还不是配送员');
|
}
|
$store_id=$detail['store_id'];
|
$store =StoreModel::detail($store_id);
|
|
if (!$store['shop_supplier_id'] > 0) {
|
return $this->renderError('未找到店铺');
|
}
|
//累积成交笔数
|
$totalCount = OrderModel::getTotalPayOrderByStore($store['store_id'],$detail['clerk_id']);
|
//今日成交笔数
|
$todayCount = OrderModel::getTodayPayOrderByStore($store['store_id'],$detail['clerk_id']);
|
//累积领取
|
$supplier = SupplierModel::detail($store['shop_supplier_id']);
|
// 订单统计 by lyzflash
|
$model = new OrderModel;
|
$orderCount = [
|
'delivery' => $model->getCount(false, 'delivery', ['clerk_id' => $this->clerk['clerk_id']]),
|
'received' => $model->getCount(false, 'received', ['clerk_id' => $this->clerk['clerk_id']]),
|
// 'refund' => $model->getCount(false, 'refund', ['store_id' => $store_id]),
|
];
|
//如果来源是小程序, 则获取小程序订阅消息id.获取订单通知.
|
$temlIds = MessageModel::getMessageByNameArr($platform, ['delivery_new_order']);
|
return $this->renderSuccess('', compact('totalCount','store' ,'todayCount', 'supplier','detail','temlIds', 'orderCount'));
|
}
|
/**
|
* 我的订单列表
|
*/
|
public function order($dataType)
|
{
|
$data = $this->postData();
|
$model = new OrderModel;
|
$user = $this->getUser();
|
|
$list = $model->getList($user['user_id'], $dataType, $data);
|
$show_alipay = PayService::isAlipayOpen($data['pay_source'], $user['app_id']);
|
return $this->renderSuccess('', compact('list', 'show_alipay'));
|
}
|
/**
|
* 提交申请
|
*/
|
public function cashsubmit($data)
|
{
|
$user = $this->getUser();
|
$detail =ClerkModel::detail(['user_id'=>$user['user_id']]);
|
if (empty($detail)) {
|
return $this->renderError('您还不是配送员');
|
}
|
|
$formData = json_decode(htmlspecialchars_decode($data), true);
|
|
// 数据验证
|
$this->validation($detail, $formData);
|
|
// 新增申请记录
|
$CashModel=new CashModel;
|
$CashModel->save(array_merge($formData, [
|
'user_id' => $user['user_id'],
|
'apply_status' => 10,
|
'app_id' => $user['app_id'],
|
]));
|
// 冻结用户资金
|
if ( $detail->freezeMoney($formData['money'])) {
|
return $this->renderSuccess('成功');
|
}
|
return $this->renderError('提交失败');
|
}
|
private function getSet()
|
{
|
//提现方式 10微信 20支付宝 30银行卡
|
$payType=['10','20','30'];
|
$settlement=['pay_type'=>$payType,'min_money'=>0.01];
|
return $settlement;
|
}
|
/**
|
* 数据验证
|
*/
|
private function validation($detail, $data)
|
{
|
// 结算设置
|
$settlement = $this->getSet();
|
// 最低提现佣金
|
if ($data['money'] <= 0) {
|
throw new BaseException(['msg' => '提现金额不正确']);
|
}
|
if ($detail['money'] <= 0) {
|
throw new BaseException(['msg' => '当前用户没有可提现佣金']);
|
}
|
if ($data['money'] > $detail['money']) {
|
throw new BaseException(['msg' => '提现金额不能大于可提现佣金']);
|
}
|
if ($data['money'] < $settlement['min_money']) {
|
throw new BaseException(['msg' => '最低提现金额为' . $settlement['min_money']]);
|
}
|
if (!in_array($data['pay_type'], $settlement['pay_type'])) {
|
throw new BaseException(['msg' => '提现方式不正确']);
|
}
|
if ($data['pay_type'] == '20') {
|
if (empty($data['alipay_name']) || empty($data['alipay_account'])) {
|
throw new BaseException(['msg' => '请补全提现信息']);
|
}
|
} elseif ($data['pay_type'] == '30') {
|
if (empty($data['bank_name']) || empty($data['bank_account']) || empty($data['bank_card'])) {
|
throw new BaseException(['msg' => '请补全提现信息']);
|
}
|
}elseif ($data['pay_type'] == '10') {
|
//微信支付需要实名认证
|
$auth = UserAuth::detail($detail['user_id']);
|
if(empty($auth)){
|
throw new BaseException(['msg' => '请先到个人中心->设置->实名认证']);
|
}elseif(!empty($auth) && $auth["auth_status"] != 1){
|
throw new BaseException(['msg' => '您的实名认证还未审核通过']);
|
}
|
}
|
}
|
/**
|
* 提现明细
|
*/
|
public function cashlists($apply_status = -1)
|
{
|
$user = $this->getUser();
|
$user_id=$user['user_id'];
|
|
$model = new CashModel;
|
$apply_status > -1 && $model = $model->where('apply_status', '=', $apply_status);
|
$list=$model->where('user_id', '=', $user_id)->order(['create_time' => 'desc'])
|
->paginate(15);
|
|
return $this->renderSuccess('', [
|
// 提现明细列表
|
'list' => $list
|
]);
|
}
|
/**
|
* 结算订单列表
|
*/
|
public function orderlists()
|
{
|
$user = $this->getUser();
|
$user_id=$user['user_id'];
|
$Clerk =ClerkModel::detail(['user_id'=>$user['user_id']]);
|
if (empty($Clerk)) {
|
return $this->renderError('您还不是配送员');
|
}
|
$store_id=$Clerk['store_id'];
|
$clerk_id = $Clerk['clerk_id'];
|
$model = new StoreOrderModel;
|
return $this->renderSuccess('', [
|
// 提现明细列表
|
'list' => $model->getSettled($store_id, (int)$clerk_id),
|
]);
|
}
|
/**
|
* 我的配送员列表
|
*/
|
public function teamlists()
|
{
|
$user = $this->getUser();
|
$ClerkGly =ClerkModel::detail(['user_id'=>$user['user_id'],'type'=>20]);
|
if (empty($ClerkGly)) {
|
return $this->renderError('您还不是门店管理员');
|
}
|
$store_id=$ClerkGly['store_id'];
|
$detail = StoreModel::detail($store_id);
|
|
$data = $this->postData();
|
$data['shop_supplier_id'] = $detail['shop_supplier_id'];
|
$search=$data['search'];
|
$model = new supplierClerkModel;
|
return $this->renderSuccess('', [
|
// 队长用户信息
|
'store' =>$detail,
|
// 我的团队列表
|
'list' => $model->getList(0,$store_id,$search,$data),
|
]);
|
}
|
|
/**
|
* 确认配送 by lyzflash
|
*/
|
public function orderDelivery($order_id)
|
{
|
$model = new OrderModel;
|
$model = $model->detail(['order_id' => $order_id, 'extract_clerk_id' => $this->clerk['clerk_id']]);
|
if (empty($model)) {
|
return $this->renderError('没有找到订单');
|
}
|
// 将订单改为已发货状态
|
if ($model->save(['delivery_status' => 20, 'delivery_time' => time()]) ) {
|
return $this->renderSuccess('成功');
|
}
|
return $this->renderError($model->getError() ?: '操作失败');
|
}
|
|
}
|