123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- /**
- * 商铺管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/31
- * Time: 15:02
- */
- namespace JinDouYun\Controller\Customer;
- use AlibabaCloud\SDK\Dingtalk\Vbizfinance_1_0\Models\QueryReceiptsBaseInfoResponseBody\list_\project;
- use JinDouYun\Model\Customer\MCustomerCard;
- use JinDouYun\Model\Department\MStaff;
- use JinDouYun\Model\Enterprise\MEnterprise;
- use JinDouYun\Model\Shop\MShopProject;
- use JinDouYun\Model\Shop\MShopRostering;
- use JinDouYun\Model\Shop\MShopSubscribe;
- use JinDouYun\Model\Shop\MShopTemplate;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Cache\ShopCache;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Shop\MShop;
- use JinDouYun\Cache\TempSaveCache;
- class CustomerCard extends BaseController
- {
- private $obj;
- private $objShopCache;
- private $objTempSaveCache;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->obj = new MCustomerCard($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objShopCache = new ShopCache();
- $this->objTempSaveCache = new TempSaveCache();
- }
- /**
- * 添加和编辑商铺管理公共字段处理方法
- *
- * @return array
- */
- public function commonFieldFilter(){
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $shopData = [
- 'uid' => isset($params['uid']) ? $params['uid'] : '',
- 'customer_id' => isset($params['customer_id']) ? $params['customer_id'] : '',
- 'project' => isset($params['project']) ? $params['project'] : '',
- 'time' => isset($params['time']) ? $params['time'] : '',
- ];
- //非暂存则验空
- if (!isset($params['tempSave']) || $params['tempSave'] == false) {
- foreach($shopData as $key => $value){
- if(empty($value) && $value !== 0){
- $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
- }
- }
- }
- $shopData['remarks']= isset($params['remarks']) ? $params['remarks'] : false;
- $shopData['pay_price']= isset($params['pay_price']) ? $params['pay_price'] : false;
- $shopData['to_price']= isset($params['to_price']) ? $params['to_price'] : false;
- $shopData['discount_price']= isset($params['discount_price']) ? $params['discount_price'] : false;
- return $shopData;
- }
- public function add()
- {
- $addStaffData = $this->commonFieldFilter();
- $project = $this->Mproject->select([['id', 'in', $addStaffData['project']]]);
- $addStaffData['shop_id'] = $this->shopId;
- $price = 0;
- $service_time = 0;
- foreach ($project as $item)
- {
- $price += $item['price'];
- $service_time += $item['service_time'];
- }
- if ($addStaffData['to_price']){
- $to_price = $addStaffData['to_price'];
- }else{
- $to_price = $price;
- }
- if ($addStaffData['pay_price']) {
- $pay_price = $addStaffData['pay_price'];
- }else{
- $pay_price = $price - $addStaffData['discount_price'];
- }
- $addStaffData['pay_price'] = $pay_price;
- $addStaffData['to_price'] = $to_price;
- $addStaffData['service_time'] = $service_time;
- $addStaffData['duration'] = $service_time;
- $result = $this->obj->insert($addStaffData);
- if ($result){
- parent::sendOutput('添加成功');
- }else{
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 修改2
- * @return void
- */
- public function update()
- {
- $id = $this->request->param('id');
- $param['project'] = $this->request->param('project');
- $param['discount_price'] = $this->request->param('discount_price');
- $param['to_price'] = $this->request->param('to_price');
- $param['pay_price'] = $this->request->param('pay_price');
- $param['time'] = $this->request->param('time');
- $param['remarks'] = $this->request->param('remarks');
- $data = $this->obj->details(['id' => $id]);
- if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
- $param['time'] = strtotime($param['time']);
- $res = $this->obj->update($param, $id);
- if ($res->isSuccess()) {
- parent::sendOutput('修改成功');
- } else {
- parent::sendOutput($res->getData(), $res->getErrorCode());
- }
- }
- /**
- * 列表
- */
- public function list()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['shop_id'] = $this->shopId;
- //昵称
- if(isset($params['nickname']) && !empty($params['nickname'])){
- $selectParams['nickname'] = $params['nickname'];
- }
- //uid
- if(isset($params['uid']) && !empty($params['uid'])){
- $selectParams['uid'] = $params['uid'];
- }
- if(isset($params['customer_id']) && !empty($params['customer_id'])){
- $selectParams['customer_id'] = $params['customer_id'];
- }
- // 时间
- if(isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])){
- $response = [];
- $dt_start = strtotime($params['start_time']);
- $dt_end = strtotime($params['end_time']);
- while ($dt_start <= $dt_end) {
- array_push($response, date('Y-m-d', $dt_start));
- $dt_start = strtotime('+1 day', $dt_start);
- }
- $selectParams['time'] = $response;
- }
- $result = $this->obj->list($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0,$pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- public function complete()
- {
- $params = $this->request->getRawJson();
- if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
- $data = $this->obj->details(['id' => $params['id']]);
- if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
- $data = $data->getData();
- if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005);
- $reward = 0;
- foreach ($data['project'] as $item){
- $reward += $item['price'] * ($item['commission']/100);
- }
- $this->staff->service($reward, $data['uid'], $this->shopId, $data['id']);
- $res = $this->obj->update(['status'=> 1, 'paid' => 1], $params['id']);
- if ($res->isSuccess()) {
- parent::sendOutput('修改成功');
- } else {
- parent::sendOutput($res->getData(), $res->getErrorCode());
- }
- }
- /**
- * 取消预约订单
- * @return void
- */
- public function cancel()
- {
- $params = $this->request->getRawJson();
- if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
- $data = $this->obj->details(['id' => $params['id']]);
- if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
- $data = $data->getData();
- if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005);
- $res = $this->obj->update(['status'=> -1], $params['id']);
- if ($res->isSuccess()) {
- parent::sendOutput('取消成功');
- } else {
- parent::sendOutput($res->getData(), $res->getErrorCode());
- }
- }
- /**
- * 详情
- * @return void
- */
- public function details()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(!empty($params['id'])){
- $selectParams['id'] = $params['id'];
- }
- $result = $this->obj->details($selectParams);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- public function delete()
- {
- $id['id'] = $this->request->param('id');
- if (empty($id['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->obj->delete($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|