Browse Source

合并商户入驻的东西过来

master
weigang 5 years ago
parent
commit
f84bbccf9e
  1. 2
      app/Constants/ErrorCode.php
  2. 6
      app/Constants/SsdbKeysPrefix.php
  3. 30
      app/Controller/StoreController.php
  4. 49
      app/Model/Store.php
  5. 83
      app/Request/StoreApplyEntryRequest.php
  6. 8
      app/Service/AttachmentService.php
  7. 104
      app/Service/StoreService.php
  8. 11
      app/Service/StoreServiceInterface.php
  9. 1
      config/autoload/dependencies.php
  10. 1
      config/autoload/middlewares.php
  11. 1
      config/routes.php

2
app/Constants/ErrorCode.php

@ -25,7 +25,7 @@ class ErrorCode extends AbstractConstants
const SERVER_ERROR = 500;
/**
* @Message("Params Invalid")
* @Message("Params Invalid!")
*/
const PARAMS_INVALID = 900;

6
app/Constants/SsdbKeysPrefix.php

@ -52,4 +52,10 @@ class SsdbKeysPrefix extends AbstractConstants
*
*/
const PURCHASE_RECORD = 'purchase_record_';
/**
* @Message("Store New User")
*/
const STORE_NEW_USER = 'store_new_user_';
}

30
app/Controller/StoreController.php

@ -7,6 +7,10 @@ use Hyperf\DbConnection\Db;
use Hyperf\HttpServer\Annotation\AutoController;
use OSS\Core\OssException;
use OSS\OssClient;
use App\Constants\ErrorCode;
use App\Request\StoreApplyEntryRequest;
use App\Service\StoreServiceInterface;
use Hyperf\Di\Annotation\Inject;
/**
* @AutoController()
@ -15,6 +19,32 @@ use OSS\OssClient;
*/
class StoreController extends BaseController
{
/**
* @Inject
* @var StoreServiceInterface
*/
protected $storeService;
/**
* 申请入驻
* 商户信息入驻+市场经理拉新记录
*/
public function applyEntry(StoreApplyEntryRequest $request)
{
$data = $request->validated();
$res = $this->storeService->entry($data);
if ($res !== true) {
return $this->result(ErrorCode::SAVE_FAILURE, $res, '申请失败,请稍后重试');
}
return $this->success('');
}
public function infoEdit()
{
$id = $this->request->input('id');

49
app/Model/Store.php

@ -1,10 +1,57 @@
<?php
declare (strict_types=1);
namespace App\Model;
/**
*/
class Store extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'ims_cjdc_store';
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'market_id',
'md_type',
'address',
'coordinates',
'details',
'link_name',
'link_tel',
'logo',
'fm_img',
'zm_img',
'yyzz',
'user_id',
'sq_id',
'admin_id',
'rz_time',
'mm_user_id',
'sq_time',
'rzdq_time',
'state',
'is_open',
'money',
'code',
'uniacid',
'zf_state',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
public $timestamps=false;
}

83
app/Request/StoreApplyEntryRequest.php

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace App\Request;
use Hyperf\Validation\Request\FormRequest;
class StoreApplyEntryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'name' => 'required|nonempty',
'market_id' => 'required|nonempty|integer',
'md_type' => 'required|nonempty|integer',
'address' => 'required|nonempty',
'coordinates' => 'required|nonempty',
'details' => 'required|nonempty',
'link_name' => 'required|nonempty',
'link_tel' => 'required|nonempty|tel',
'logo' => 'required|nonempty|image_if_file',
'fm_img' => 'required|nonempty|image_if_file|file_different_if_file:zm_img',
'zm_img' => 'required|nonempty|image_if_file|file_different_if_file:fm_img',
'yyzz' => 'required|nonempty|image_if_file',
'user_id' => 'required|nonempty|integer',
'rz_time' => 'required|nonempty|integer',
'mm_user_id' => 'nonempty|integer',
'id' => 'nonempty|integer',
];
}
public function messages(): array
{
return [
'*.nonempty' => ':attribute参数异常',
'logo.image' => ':attribute不是正常的图片',
'logo.*' => ':attribute未选择',
'fm_img.image' => ':attribute不是正常的图片',
'fm_img.file_different_if_file' => '身份证正反面不能相同',
'fm_img.*' => ':attribute未选择',
'zm_img.image' => ':attribute不是正常的图片',
'zm_img.file_different_if_file' => '身份证正反面不能相同',
'zm_img.*' => ':attribute未选择',
'yyzz.image' => ':attribute不是正常的图片',
'yyzz.*' => ':attribute未选择',
'link_tel.tel' => ':attribute格式不正确',
];
}
public function attributes(): array
{
return [
'name' => '商户名',
'market_id' => '市场ID',
'md_type' => '门店类型',
'address' => '门店地址',
'coordinates' => '门店经纬度',
'details' => '门店简介',
'link_name' => '联系人姓名',
'link_tel' => '联系人电话',
'logo' => '商户LOGO',
'fm_img' => '商户身份证反面',
'zm_img' => '商户身份证正面',
'yyzz' => '商户营业执照',
'user_id' => '申请用户ID',
'rz_time' => '入驻天数',
'mm_user_id' => '市场经理用户ID',
'id' => '门店ID',
];
}
}

8
app/Service/AttachmentService.php

@ -21,6 +21,10 @@ class AttachmentService implements AttachmentServiceInterface
$path = $this->getBasePath($path, $attachmenttype);
$fileName = $path . '/' . $fileHash . '.' . $file->getExtension();
if ($filesystem->has($fileName)) {
return $fileName;
}
$stream = fopen($fileRealPath, 'r+');
$filesystem->writeStream($fileName, $stream);
fclose($stream);
@ -45,6 +49,10 @@ class AttachmentService implements AttachmentServiceInterface
$path = $this->getBasePath($path);
$fileName = $path . '/' . $fileHash . '.' . $result[2];
if ($filesystem->has($fileName)) {
return $fileName;
}
$filesystem->write($fileName, $contents);
return $fileName;

104
app/Service/StoreService.php

@ -0,0 +1,104 @@
<?php
namespace App\Service;
use App\Constants\LogLabel;
use App\Constants\SsdbKeysPrefix;
use App\Model\Store;
use App\TaskWorker\SSDBTask;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Upload\UploadedFile;
use Hyperf\Utils\ApplicationContext;
use League\Flysystem\Filesystem;
class StoreService implements StoreServiceInterface
{
/**
* @Inject
* @var AttachmentServiceInterface
*/
protected $attachmentService;
/**
* @Inject
* @var Filesystem
*/
protected $filesystem;
public function entry($data)
{
Db::beginTransaction();
try {
// 文件上传
if ($data['logo'] instanceof UploadedFile) {
$data['logo'] = $this->attachmentService->formUpload($data['logo'], 'storelogo', $this->filesystem);
}
if ($data['fm_img'] instanceof UploadedFile) {
$data['fm_img'] = $this->attachmentService->formUpload($data['fm_img'], 'idcard', $this->filesystem);
}
if ($data['zm_img'] instanceof UploadedFile) {
$data['zm_img'] = $this->attachmentService->formUpload($data['zm_img'], 'idcard', $this->filesystem);
}
if ($data['yyzz'] instanceof UploadedFile) {
$data['yyzz'] = $this->attachmentService->formUpload($data['yyzz'], 'storelicense', $this->filesystem);
}
// 商户信息入库(需审核)
$store = Store::query()->updateOrCreate(
['id' => $data['id']],
[
'name' => $data['name'],
'market_id' => $data['market_id'],
'md_type' => $data['md_type'],
'address' => $data['address'],
'coordinates' => $data['coordinates'],
'details' => $data['details'],
'link_name' => $data['link_name'],
'link_tel' => $data['link_tel'],
'tel' => $data['link_tel'],
'logo' => $data['logo'],
'fm_img' => $data['fm_img'],
'zm_img' => $data['zm_img'],
'yyzz' => $data['yyzz'],
'user_id' => $data['user_id'],
'sq_id' => $data['user_id'],
'admin_id' => $data['user_id'],
'rz_time' => $data['rz_time'],
'mm_user_id' => $data['mm_user_id'],
'sq_time' => date('Y-m-d H:i:s'),
'rzdq_time' => date('Y-m-d H:i:s', time() + 1000 * 24 * 3600),
'state' => 1,
'is_open' => 1,
'money' => 0,
'code' => time() . rand(1000, 9999) . $data['user_id'],
'uniacid' => 2,
'zf_state' => 2,
]
);
Db::commit();
// 商户新用户等统计信息入SSDB
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
if (!$ssdb->exec('hexists', SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'count')) {
if(false === $ssdb->exec('hset', SsdbKeysPrefix::STORE_NEW_USER.$store->id, ['count', 0])) {
$this->log->event(
LogLabel::SSDB_LOG,
['method' => 'hset-'.SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'key' => SsdbKeysPrefix::STORE_NEW_USER.$store->id]
);
}
}
return true;
} catch (\Exception $e) {
Db::rollBack();
return $e->getMessage();
}
}
}

11
app/Service/StoreServiceInterface.php

@ -0,0 +1,11 @@
<?php
namespace App\Service;
interface StoreServiceInterface
{
/**
* 入驻
*/
public function entry($data);
}

1
config/autoload/dependencies.php

@ -35,4 +35,5 @@ return [
\App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class,
\App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class,
\App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class,
\App\Service\StoreServiceInterface::class => \App\Service\StoreService::class,
];

1
config/autoload/middlewares.php

@ -13,5 +13,6 @@ return [
'http' => [
\App\Middleware\CorsMiddleware::class,
\Hyperf\Validation\Middleware\ValidationMiddleware::class,
\App\Middleware\Auth\ApiMiddleware::class,
],
];

1
config/routes.php

@ -66,6 +66,7 @@ Router::addGroup('/v1/',function (){
Router::post('PurchaseLimit/getStoreIdByMarketId', 'App\Controller\PurchaseLimitController@getStoreIdByMarketId');
Router::post('OrderList/storeOrderList', 'App\Controller\OrderListController@storeOrderList');
Router::post('OrderList/userOrderList', 'App\Controller\OrderListController@userOrderList');
Router::post('Store/applyEntry', 'App\Controller\StoreController@applyEntry');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);

Loading…
Cancel
Save