123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- /**
- * 商铺管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/31
- * Time: 15:02
- */
- namespace JinDouYun\Model\Shop;
- use AlibabaCloud\SDK\Dingtalk\Vcrm_1_0\Models\DescribeRelationMetaResponseBody\relationMetaDTOList\items\props\fields\relateProps;
- use Exception;
- use JinDouYun\Controller\Common\Logger;
- use JinDouYun\Dao\Department\DStaff;
- use JinDouYun\Dao\GoodsManage\DGoodsBasic;
- use JinDouYun\Dao\Shop\DShopProject;
- use JinDouYun\Dao\Shop\DShopRostering;
- use JinDouYun\Dao\Shop\DShopTemplate;
- use JinDouYun\Dao\UserCenter\DUserCenter;
- use JinDouYun\Model\Common\Location;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Shop\DShop;
- use JinDouYun\Dao\Shop\DEnterpriseBindShop;
- use Jindouyun\Cache\EnterpriseCache;
- use JinDouYun\Cache\RoleAclCache;
- use JinDouYun\Cache\ShopCache;
- use JinDouYun\Cache\SysAreaChinaCache;
- use JinDouYun\Cache\GoodsBasicRelevant;
- use JinDouYun\Model\ShopPartner\MShopPartner;
- use JinDouYun\Model\Stock\MWarehouse;
- use JinDouYun\Model\SysAreaChina\MSysAreaChina;
- use JinDouYun\Model\Customer\MCustomer;
- use JinDouYun\Model\Enterprise\MEnterprise;
- use JinDouYun\Model\Department\MStaff;
- use JinDouYun\Model\MBaseModel;
- use Monolog\Handler\IFTTTHandler;
- class MShopRostering extends MBaseModel
- {
- private $obj;
- private $cutTable = 250000;
- private $enterpriseId;
- private $userCenterId;
- private $objDShopTemplate;
- private $objStaff;
- public function __construct($enterpriseId, $userCenterId = '')
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- parent::__construct($this->enterpriseId, $this->userCenterId);
- $this->obj = new DShopRostering('default');
- $this->objDShopTemplate = new DShopTemplate('default');
- $this->objStaff = new DStaff('default');
- $this->obj->setTable('qianniao_shop_rostering_'.$enterpriseId);
- $this->objStaff->setTable('qianniao_staff_'.$enterpriseId);
- }
- /**
- * 列表
- * @param $where
- * @return mixed
- */
- public function list($where)
- {
- $limit = $where['limit'];
- unset($where['limit']);
- $offset = $where['offset'];
- unset($where['offset']);
- $file = ' a.*,b.staffName';
- $sql = 'SELECT'.$file.' FROM qianniao_shop_rostering'.$this->enterpriseId.' AS a
- LEFT JOIN qianniao_staff_'.$this->enterpriseId.' AS b ON a.uid = b.userCenterId
- WHERE a.shop_id = '. $where['shop_id'];
- if(isset($where['nickname'])) {
- $sql .= ' AND b.staffName LIKE "%' . $where['nickname'] . '%"';
- }
- if(isset($where['uid'])) {
- $sql .= ' AND a.uid = '.$where['uid'];
- }
- if(isset($where['time'])) {
- $time_field = '';
- foreach ($where['time'] as $item)
- {
- $time_field .= '"'.$item.'",';
- }
- $time_field = rtrim($time_field, ',');
- $sql .= ' AND a.time in ('.$time_field.')';
- }
- $total = count((array) $this->obj->query($sql));
- $sql .= ' ORDER BY createTime DESC LIMiT '.$offset.','.$limit;
- $dbResult = $this->obj->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- foreach ($dbResult as &$item)
- {
- $temsql = 'SELECT * FROM qianniao_shop_template WHERE id IN ('.$item['template_id'].')';
- $item['template'] = $this->objDShopTemplate->query($temsql);
- }
- $return = [
- 'data' => $dbResult,
- 'total' => ($total) ? intval($total) : 0,
- ];
- if($return === false){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($return);
- }
- }
- /**
- * 详情
- * @param $where
- * @return mixed
- */
- public function details($where)
- {
- if(empty($where)){
- return ResultWrapper::success($where);
- }
- $dbResult = $this->obj->get($where);
- if(empty($dbResult)){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- $temsql = 'SELECT * FROM qianniao_shop_template WHERE id IN ('.$dbResult['template_id'].')';
- $dbResult['template'] = $this->objDShopTemplate->query($temsql);
- return ResultWrapper::success(self::formatInfo($dbResult));
- }
- /**
- * Doc: (des="添加")
- * User: XMing
- * Date: 2020/7/15
- * Time: 10:42 上午
- * @throws Exception
- * @param array $params
- * @return ResultWrapper
- */
- public function insert(array $params)
- {
- // $times = $params['times'];
- // unset($params['times']);
- //
- //
- $this->obj->beginTransaction();
- $data = $this->obj->get(['uid' => $params['uid'], 'time' => $params['time']]);
- if ($data){
- $res = $this->obj->update([
- 'name' => $params['name'],
- 'template_id' => $params['template_id'],
- 'time' => $params['time'],
- 'time_slot' => $params['time_slot'],
- ], $data['id']);
- }else{
- $res = $this->obj->insert($params);
- }
- if ($res){
- $this->obj->commit();
- return ResultWrapper::success('添加成功');
- }else{
- $this->obj->rollBack();
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- }
- public function update($params, $id)
- {
- $data = $this->obj->get($id);
- if (!$data){
- return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
- }
- $dbResult = $this->obj->update($params,$id);
- if($dbResult === false){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success('修改成功');
- }
- public function select($where = null, $fields = '*', $order = null, $limit = null, $offset = null, $data = array(), $multiple = true, $isExport = false)
- {
- if (isset($where['export'])){
- unset($where['export']);
- $data = $this->obj->select($where);
- foreach ($data as &$item)
- {
- $staff = $this->objStaff->get(['id' => $item['uid']]);
- $item['staffName'] = $staff['staffName'];
- $item['avatar'] = $staff['avatar'];
- $item['evaluate'] = $staff['evaluate'];
- $item['info'] = $staff['info'];
- }
- $this->Excel($data);
- exit;
- }
- $data = $this->obj->select($where, $fields, $order, $limit, $offset, $data, $multiple, $isExport);
- $count = $this->obj->count($where);
- if($data === false){
- return ResultWrapper::success($data);
- }else{
- foreach ($data as &$item)
- {
- $staff = $this->objStaff->get(['id' => $item['uid']]);
- $item['staffName'] = $staff['staffName'];
- $item['avatar'] = $staff['avatar'];
- $item['evaluate'] = $staff['evaluate'];
- $item['info'] = $staff['info'];
- $item['time_slot'] = json_decode($item['time_slot']);
- $item['clock'] = json_decode($item['clock']);
- }
- $return = [
- 'data' => $data,
- 'total' => $count,
- ];
- return ResultWrapper::success($return);
- }
- }
- /**
- * 导出
- * @param $inventoryOutData
- * @return void
- *
- */
- public function Excel($data)
- {
- //导出到本地
- header("Content-type:application/vnd.ms-excel");
- header("Content-Disposition:filename=考情记录.csv");
- header('Cache-Control: max-age=0');
- $fp = fopen('php://output', 'a');
- $head = ['ID', '员工名称','排班日期','排班时间', '打卡记录']; //定义标题
- foreach ($head as $i => $v) {
- $head[$i] = mb_convert_encoding($v, 'GBK', 'utf-8'); //将中文标题转换编码,否则乱码
- }
- fputcsv($fp, $head);
- $limit = 10000;
- $num = 0;//计数器
- foreach ($data as $value) {//循环数据
- $num++;
- if ($num == $limit) {
- ob_flush();//释放内存
- flush();
- }
- $clockData = [];
- if (!empty($value['clock'])){
- $clock = json_decode($value['clock']);
- foreach ($clock as $item)
- {
- $clockStr = '';
- if ($item->timeResult == 'NotSigned') $clockStr = '未打卡';
- if ($item->timeResult == 'Late') $clockStr = '迟到';
- if ($item->timeResult == 'Early') $clockStr = '早退';
- if ($item->timeResult == 'Normal') $clockStr = '正常';
- $clockData[] = [
- $item->baseCheckTime,
- $item->userCheckTime,
- $clockStr,
- ];
- }
- }
- $rows['id'] = isset($value['id']) ? $value['id'] : null; // ID
- $rows['staffName'] = isset($value['staffName']) ? $value['staffName'] : null; // 员工名称
- $rows['time'] = isset($value['time']) ? $value['time'] : null;
- $rows['time_slot'] = isset($value['time_slot']) ? $value['time_slot'] : null;
- $rows['clock'] = isset($value['clock']) ? json_encode($clockData) : '没有打卡记录';
- foreach ($rows as $kk => $vv) {
- $rs[$kk] = mb_convert_encoding($vv, 'GBK', 'utf-8'); //转译编码
- }
- fputcsv($fp, $rs);
- $rows = [];
- }
- }
- /**
- * 格式数据详情
- * @param $data
- * @return mixed
- */
- public function formatInfo($data)
- {
- return $data;
- }
- public function delete($id)
- {
- $res = $this->obj->delete(['id' => $id]);
- if ($res){
- return ResultWrapper::success('删除成功');
- }
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- }
|