Consult.php 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  47. if ($start !="") {
  48. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  49. $where[]= ["a.addtime",'>=',$start];
  50. }
  51. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  52. if($end !=""){
  53. $where[]= ["a.addtime",'<=',$end];
  54. }
  55. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  56. if ($status !== "") {
  57. $where[]= ["a.status",'=',$status];
  58. }
  59. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  60. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  61. // $role=$this->checkRole();
  62. // if(!empty($role['write'])){
  63. // $where[]=["b.createrid","in",$role['write']];
  64. // }
  65. $role = $this->checkDataShare();
  66. if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  67. // if(!empty($role['platform']) ){
  68. // $where[]=["b.platform_code","in",$role['platform']];
  69. // }
  70. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  71. ->count();
  72. $total = ceil($count / $size);
  73. $page = $page >= $total ? $total : $page;
  74. $list = Db::name('consult_info')
  75. ->alias("a")
  76. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  77. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  78. ->where($where)
  79. ->page($page, $size)
  80. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  81. ->order("a.id desc")
  82. ->cursor();
  83. $data=[];
  84. foreach ($list as $value){
  85. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  86. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  87. true):[];
  88. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  89. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  90. $value['khname']="";
  91. if($value['khNo']!==""){
  92. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  93. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  94. }
  95. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  96. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  97. //是否具有编辑权限
  98. $value['is_allow_update'] = 0;
  99. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  100. $data[]=$value;
  101. }
  102. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  103. }
  104. public function info(){
  105. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  106. if($id==""){
  107. return error_show(1002,"咨询单编号不能为空");
  108. }
  109. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  110. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  111. $fo['can']=$in;
  112. if(empty($fo)){
  113. return error_show(1002,"未找到咨询单编号");
  114. }else{
  115. return app_show(0,"获取成功",$fo);
  116. }
  117. }
  118. public function del(){
  119. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  120. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  121. if($de==false){
  122. return error_show(1002,'咨询单信息未找到');
  123. }
  124. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  125. if($dell){
  126. return error_show(0,"删除成功");
  127. }else
  128. return error_show(1002,"删除失败");
  129. }
  130. public function create(){
  131. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  132. if($is_project===""){
  133. return error_show(1002,"参数is_project不能为空");
  134. }
  135. if($is_project==1){
  136. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  137. if($projectNo===""){
  138. return error_show(1002,"参数projectNo不能为空");
  139. }
  140. }
  141. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  142. if($khNo===""){
  143. return error_show(1002,"参数khNo不能为空");
  144. }
  145. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  146. if($companyNo===""){
  147. return error_show(1002,"参数companyNo不能为空");
  148. }
  149. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  150. if($endtime===""){
  151. return error_show(1002,"参数endtime不能为空");
  152. }
  153. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  154. "";
  155. if($platform_code===""){
  156. return error_show(1002,"参数platform_code不能为空");
  157. }
  158. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  159. if($ladder==""){
  160. return error_show(1005,"参数ladder不能为空");
  161. }
  162. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  163. if($token==''){
  164. return error_show(105,"参数token不能为空");
  165. }
  166. $user =GetUserInfo($token);
  167. if(empty($user)||$user['code']!=0){
  168. return error_show(102,"用户数据不存在");
  169. }
  170. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  171. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  172. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  173. $zxNo=makeNo("ZX");
  174. Db::startTrans();
  175. try{
  176. $data=[
  177. "zxNo"=>$zxNo,
  178. "createrid"=>$createrid,
  179. "creater"=>$creater,
  180. "is_project"=>$is_project,
  181. "projectNo"=>isset($projectNo) ? $projectNo:"",
  182. "khNo"=>$khNo,
  183. "companyNo"=>$companyNo,
  184. "endtime"=>$endtime,
  185. "salesman"=>$creater,
  186. "platform_code"=>$platform_code,
  187. "saleid"=>$createrid,
  188. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  189. "status"=>0,
  190. "is_del"=>0,
  191. "addtime"=>date("Y-m-d H:i:s"),
  192. "updatetime"=>date("Y-m-d H:i:s"),
  193. ];
  194. $zx = Db::name("consult_order")->insert($data);
  195. if($zx){
  196. //判断是否是项目,且该项目是否存在台账记录中
  197. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  198. foreach ($ladder as $value){
  199. $infoNo=makeNo("IF");
  200. $specinfo=[];
  201. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  202. foreach ($value["specinfo"] as $v){
  203. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  204. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  205. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  206. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  207. $specinfo[]=$v;
  208. }
  209. }
  210. $info=[
  211. "infoNo"=>$infoNo,
  212. "zxNo"=>$zxNo,
  213. "spuCode"=>"",
  214. "good_name"=>$value['good_name'],
  215. "good_img"=>$value['good_img'],
  216. "cat_id"=>$value['cat_id'],
  217. "unit"=>$value['unit'],
  218. "brand_id"=>$value['brand_id'],
  219. "arrival_time"=>$value['arrival_time'],
  220. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  221. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  222. "is_addrs"=>$value['is_addrs'],
  223. "is_custom"=>$value['is_custom'],
  224. "metal_id"=>$value['metal_id'],
  225. "config"=>isset($value['config'])?$value['config']:"",
  226. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  227. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  228. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  229. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  230. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  231. "budget_price"=>$value['budget_price'],
  232. "num"=>$value['num'],
  233. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  234. "use_desc"=>$value['use_desc'],
  235. "remark"=>$value['remark'],
  236. "status"=>1,
  237. "is_del"=>0,
  238. "addtime"=>date("Y-m-d H:i:s"),
  239. "updatetime"=>date("Y-m-d H:i:s"),
  240. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  241. ];
  242. $up = Db::name("consult_info")->insertGetId($info);
  243. if(!$up){
  244. Db::rollback();
  245. return error_show(1004,'添加失败');
  246. }else{
  247. //修改状态
  248. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  249. "order_code" => $infoNo,//咨询单详情编号
  250. "status" => 1,//这里的status是之前的值
  251. "action_remark" => '',//备注
  252. "action_type" => "create"//新建create,编辑edit,更改状态status
  253. ], "ZXD", 1, $info);
  254. //竞价单不走流程,不推待办已办
  255. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  256. // "order_type" => 'ZXD',
  257. // "order_code" => $infoNo,//咨询单详情编号
  258. // "order_id" => $up,
  259. // "order_status" => 1,
  260. // 'before_status'=>0
  261. // ]);
  262. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  263. if (isset($stand_exists)) {
  264. Db::name('standing_book')
  265. ->where('id', $stand_exists['id'])
  266. ->update([
  267. 'infoNo' => $infoNo,
  268. 'updatetime' => date('Y-m-d H:i:s')
  269. ]);
  270. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  271. } else {
  272. //添加台账信息
  273. Db::name('standing_book')
  274. ->insert([
  275. 'standBookNo' => makeNo("IO"),
  276. 'projectNo' => isset($projectNo) ? $projectNo : '',
  277. 'infoNo' => $infoNo,
  278. 'companyNo' => $companyNo,
  279. 'customer_code' => $khNo,
  280. 'addtime' => date('Y-m-d H:i:s'),
  281. 'updatetime' => date('Y-m-d H:i:s')
  282. ]);
  283. }
  284. }
  285. }
  286. Db::commit();
  287. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  288. }else{
  289. Db::rollback();
  290. return error_show(1004,"新建失败");
  291. }
  292. }catch (\Exception $e){
  293. Db::rollback();
  294. return error_show(1003,$e->getMessage());
  295. }
  296. }
  297. public function zxinfo(){
  298. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  299. if($infoNo==""){
  300. return error_show(1004,"参数infoNo不能为空");
  301. }
  302. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  303. if($zxinfo==false){
  304. return error_show(1004,"未找到信息数据");
  305. }
  306. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  307. if($zxorder==false){
  308. return error_show(1004,"未找到咨询信息数据");
  309. }
  310. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  311. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  312. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  313. $zxinfo['khname']="";
  314. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  315. $zxinfo['khNo']="";
  316. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  317. $zxinfo['brand']="";
  318. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  319. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  320. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  321. $zxinfo['company']="";
  322. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  323. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  324. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  325. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  326. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  327. $zxinfo['project_name']="";
  328. $zxinfo['budget_total']="";
  329. $zxinfo['departinfo']=[];
  330. $zxinfo['unit_name']="";
  331. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  332. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  333. if($zxorder['khNo']!==""){
  334. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  335. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  336. $zxinfo['khNo']= $zxorder['khNo'];
  337. }
  338. if($zxinfo['unit']!==""){
  339. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  340. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  341. }
  342. if($zxinfo['brand_id']!==""){
  343. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  344. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  345. }
  346. if($zxorder['companyNo']!==""){
  347. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  348. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  349. }
  350. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  351. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  352. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  353. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  354. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  355. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  356. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  357. }
  358. if($zxorder['depart']>0){
  359. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  360. }
  361. if($zxorder['platform_code']>0){
  362. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  363. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  364. }
  365. return app_show(0,"获取成功",$zxinfo);
  366. }
  367. public function zxedit(){
  368. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  369. if($infoNo==""){
  370. return error_show(1004,"参数infoNo不能为空");
  371. }
  372. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  373. if($zxinfo==false){
  374. return error_show(1004,"未找到信息数据");
  375. }
  376. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  377. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  378. if($good_name==""){
  379. return error_show(1003,"参数good_name不能为空");
  380. }
  381. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  382. if($good_img==""){
  383. return error_show(1003,"参数good_img不能为空");
  384. }
  385. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  386. if($cat_id==""){
  387. return error_show(1003,"参数cat_id不能为空");
  388. }
  389. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  390. if($unit==""){
  391. return error_show(1003,"参数unit不能为空");
  392. }
  393. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  394. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  395. if($arrival_time==""){
  396. return error_show(1003,"参数arrival_time不能为空");
  397. }
  398. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  399. if($specin==""){
  400. return error_show(1003,"参数specinfo不能为空");
  401. }
  402. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  403. // if($cost_desc==""){
  404. // return error_show(1003,"参数cost_desc不能为空");
  405. // }
  406. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  407. if($is_addrs===""){
  408. return error_show(1003,"参数is_addrs不能为空");
  409. }
  410. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  411. if($is_custom===""){
  412. return error_show(1003,"参数is_custom不能为空");
  413. }
  414. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  415. if($metal_id===""){
  416. return error_show(1003,"参数metal_id不能为空");
  417. }
  418. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  419. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  420. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  421. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  422. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  423. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  424. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  425. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  426. if($num===""){
  427. return error_show(1003,"参数num不能为空");
  428. }
  429. if($budget_price===""){
  430. return error_show(1003,"参数budget_price不能为空");
  431. }
  432. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  433. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  434. if($use_desc==""){
  435. return error_show(1003,"参数use_desc不能为空");
  436. }
  437. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  438. if($remark==""){
  439. return error_show(1003,"参数remark不能为空");
  440. }
  441. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  442. if($endtime==""){
  443. return error_show(1003,"参数endtime不能为空");
  444. }
  445. if($metal_id!=0){
  446. if($config==""){
  447. return error_show(1003,"参数config不能为空");
  448. }
  449. if($other_config==""){
  450. return error_show(1003,"参数other_config不能为空");
  451. }
  452. if($specs_weight===""){
  453. return error_show(1003,"参数specs_weight不能为空");
  454. }
  455. if($gold_price===""){
  456. return error_show(1003,"参数gold_price不能为空");
  457. }
  458. }
  459. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  460. if($token==''){
  461. return error_show(102,"参数token不能为空");
  462. }
  463. $user =GetUserInfo($token);
  464. if(empty($user)||$user['code']!=0){
  465. return error_show(105,"用户数据不存在");
  466. }
  467. $specinfo=[];
  468. foreach ($specin as $v){
  469. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  470. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  471. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  472. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  473. $specinfo[]=$v;
  474. }
  475. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  476. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  477. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  478. Db::startTrans();
  479. try{
  480. $innew =makeNo("IF");
  481. $info=[
  482. "infoNo"=>$innew,
  483. "zxNo"=>$zxinfo['zxNo'],
  484. "spuCode"=>"",
  485. "good_name"=>$good_name,
  486. "good_img"=>$good_img,
  487. "cat_id"=>$cat_id,
  488. "unit"=>$unit,
  489. "brand_id"=>$brand_id,
  490. "arrival_time"=>$arrival_time,
  491. "specinfo"=>json_encode($specinfo),
  492. // "color"=>$color,
  493. // "material"=>$material,
  494. "cost_desc"=>$cost_desc,
  495. "is_addrs"=>$is_addrs,
  496. "is_custom"=>$is_custom,
  497. "metal_id"=>$metal_id,
  498. "config"=>$config,
  499. "other_config"=>$other_config,
  500. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  501. "gold_price"=>$gold_price===""? 0 : $gold_price,
  502. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  503. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  504. "budget_price"=>$budget_price,
  505. "num"=>$num,
  506. "pgNo"=>$pgNo,
  507. "use_desc"=>$use_desc,
  508. "remark"=>$remark,
  509. "bargain_num"=>$zxinfo['bargain_num']+1,
  510. "status"=>1,
  511. "is_del"=>0,
  512. "addtime"=>date("Y-m-d H:i:s"),
  513. "updatetime"=>date("Y-m-d H:i:s"),
  514. 'bargain_status'=>1,
  515. 'enclosure_file'=>$enclosure_file
  516. ];
  517. $up = Db::name("consult_info")->insert($info);
  518. if($up){
  519. //操作记录
  520. ActionLog::logAdd($this->post['token'], [
  521. "order_code" => $innew,//咨询单详情编号
  522. "status" => 1,//这里的status是之前的值
  523. "action_remark" => '',//备注
  524. "action_type" => "edit"//新建create,编辑edit,更改状态status
  525. ], "ZXD", 1, $this->post);
  526. // ProcessOrder::AddProcess($this->post['token'], [
  527. // "order_type" => 'ZXD',
  528. // "order_code" => $innew,//咨询单详情编号
  529. // "order_id" => 0,
  530. // "order_status" => 1
  531. // ]);
  532. if (!empty($bidlist)){
  533. foreach ($bidlist as $value){
  534. unset($value['id']);
  535. $value['infoNo']=$innew;
  536. $value['bidNo']=makeNo("BD");
  537. $value['spuCode']=makeNo("SKU");
  538. $value['status'] =0;
  539. $value['updatetime'] =date("Y-m-d H:i:s");
  540. $in = Db::name("consult_bids")->insert($value);
  541. if($in==false){
  542. Db::rollback();
  543. return error_show(1004,"反馈商品新建失败");
  544. }
  545. ActionLog::logAdd($this->post['token'], [
  546. "order_code" => $innew,//咨询单详情编号
  547. "status" => 1,//这里的status是之前的值
  548. "action_remark" => '',//备注
  549. "action_type" => "edit"//新建create,编辑edit,更改状态status
  550. ], "FKD", 1, $this->post);
  551. }
  552. }
  553. $zxinfo["bargain_status"] =1;
  554. $zxinfo["status"] =6;
  555. $zxinfo["bargain_code"] =$innew;
  556. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  557. $bar=Db::name("consult_info")->save($zxinfo);
  558. if($bar==false){
  559. Db::rollback();
  560. return error_show(1004,"反馈商品更新失败");
  561. }else{
  562. //修改状态,添加待办
  563. ActionLog::logAdd($this->post['token'], [
  564. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  565. "status" => $zxinfo['status'],//这里的status是之前的值
  566. "action_remark" => '',//备注
  567. "action_type" => "edit"//新建create,编辑edit,更改状态status
  568. ], "ZXD", $zxinfo['status'], $zxinfo);
  569. }
  570. //更新consule_order记录
  571. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  572. 'updatetime'=>date('Y-m-d H:i:s')]);
  573. if($op==false){
  574. Db::rollback();
  575. return error_show(1004,'咨询单结束时间更新失败');
  576. }
  577. //维护台账记录
  578. $insert_standing_book_data=[
  579. 'standBookNo'=>makeNo('IO'),
  580. 'infoNo'=>$innew,
  581. 'addtime' => date('Y-m-d H:i:s'),
  582. 'updatetime' => date('Y-m-d H:i:s')
  583. ];
  584. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  585. if(!empty($temp_project)){
  586. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  587. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  588. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  589. }
  590. Db::name('standing_book')->insert($insert_standing_book_data);
  591. Db::commit();
  592. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  593. }
  594. }catch (\Exception $e){
  595. Db::rollback();
  596. return error_show(1004,$e->getMessage());
  597. }
  598. }
  599. //** 发布竞标任务 */
  600. public function bargain(){
  601. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  602. if($infoNo==""){
  603. return error_show(1004,"参数infoNo不能为空");
  604. }
  605. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  606. if($zxinfo==false){
  607. return error_show(1004,"未找到信息数据");
  608. }
  609. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  610. if($status===""){
  611. return error_show(1004,"参数status不能为空");
  612. }
  613. // if($status==1&&$zxinfo['status']>1){
  614. // $zxinfo['bargain_num']=+1;
  615. // }
  616. $old_zxinfo_status = $zxinfo['status'];
  617. $zxinfo['status']=$status;
  618. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  619. $up = Db::name("consult_info")->save($zxinfo);
  620. if($up){
  621. //修改状态,添加待办
  622. ActionLog::logAdd($this->post['token'], [
  623. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  624. "status" => $old_zxinfo_status,//这里的status是之前的值
  625. "action_remark" => '',//备注
  626. "action_type" => "status"//新建create,编辑edit,更改状态status
  627. ], "ZXD", $zxinfo['status'], $zxinfo);
  628. return app_show(0,"状态更新成功");
  629. }else{
  630. return error_show(1003,"状态更新失败");
  631. }
  632. }
  633. //反馈商品添加
  634. public function feadback(){
  635. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  636. if($infoNo==""){
  637. return error_show(1002,"参数infoNo不能为空");
  638. }
  639. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  640. if($zxinfo==false){
  641. return error_show(1003,"未找到信息数据");
  642. }
  643. if($zxinfo['status']!=1){
  644. return error_show(1004,"任务未进行");
  645. }
  646. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  647. if($zx==false){
  648. return error_show(1003,"未找咨询信息数据");
  649. }
  650. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  651. if($pname==""){
  652. return error_show(1002,"参数pname不能为空");
  653. }
  654. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  655. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  656. if($cat_id==""){
  657. return error_show(1002,"参数cat_id不能为空");
  658. }
  659. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  660. if($specin==""){
  661. return error_show(1003,"参数specinfo不能为空");
  662. }
  663. $specinfo=[];
  664. foreach ($specin as $v){
  665. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  666. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  667. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  668. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  669. $specinfo[]=$v;
  670. }
  671. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  672. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  673. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  674. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  675. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  676. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  677. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  678. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  679. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  680. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  681. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  682. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  683. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  684. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  685. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  686. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  687. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  688. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  689. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  690. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  691. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  692. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  693. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  694. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  695. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  696. if($nake_fee==="" ){
  697. return error_show(1004,"参数nake_fee不能为空");
  698. }
  699. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  700. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  701. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  702. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  703. if($delivery_place==''){
  704. return error_show(1002,"参数delivery_place不能为空");
  705. }
  706. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  707. if($token==''){
  708. return error_show(1002,"参数token不能为空");
  709. }
  710. $user =GetUserInfo($token);
  711. if(empty($user)||$user['code']!=0){
  712. return error_show(1005,"用户数据不存在");
  713. }
  714. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  715. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  716. $bidNo=makeNo("BD");
  717. $spucode=makeNo("SKU");
  718. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  719. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  720. //部分参数的大小校验
  721. $vali = Validate::rule([
  722. 'expire_day|有效时长'=>'require|elt:214748364',
  723. 'delivery_day|物流时长'=>'require|elt:214748364',
  724. 'work_day|生产工期'=>'require|elt:214748364',
  725. 'weight|总重量'=>'require|max:10',
  726. ]);
  727. $temp = [
  728. 'expire_day'=>$expire_day,
  729. 'delivery_day'=>$delivery_day,
  730. 'work_day'=>$work_day,
  731. 'weight'=>$weight,
  732. ];
  733. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  734. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  735. $cat_top_list = made($cat_id);
  736. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  737. if ($is_gold_price == 1 && $cat_top_id == 6) {
  738. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  739. ->find();
  740. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  741. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  742. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  743. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  744. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  745. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  746. $saleprice = $total_fee/ (1 - $budget);
  747. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  748. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  749. }else{
  750. if($nake_fee){
  751. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  752. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  753. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  754. }else{
  755. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  756. (1 - $budget);
  757. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  758. }
  759. }
  760. $supplier = Db::name('supplier')
  761. ->field('id,person,personid')
  762. ->where('code',$supplierNo)
  763. ->findOrEmpty();
  764. $data=[
  765. "bidNo"=>$bidNo,
  766. "infoNo"=>$infoNo,
  767. "zxNo"=>$zxinfo['zxNo'],
  768. "spuCode"=>$spucode,
  769. "good_name"=>$pname,
  770. "brand_id"=>$brandid,
  771. "cat_id"=>$cat_id,
  772. "specinfo"=>json_encode($specinfo),
  773. "unit_id"=>$unit_id,
  774. "cost_desc"=>$cost_desc,
  775. "work_day"=>$work_day,
  776. "delivery_day"=>$delivery_day,
  777. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  778. "expire_day"=>$expire_day,
  779. "origin_place"=>$origin_place,
  780. "supplierNo"=>$supplierNo,
  781. "pay_way"=>$pay_way,
  782. "tax"=>$tax,
  783. "send_way"=>$send_way,
  784. "metal_id"=>$metal_id,
  785. "is_gold_price"=>$is_gold_price,
  786. "config"=>$config,
  787. "other_config"=>$other_config,
  788. "weight"=>$weight,
  789. "good_weight"=>$good_weight,
  790. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  791. "is_diff"=>$is_diff,
  792. "demo_fee"=>$demo_fee,
  793. "delivery_fee"=>$delivery_fee,
  794. "open_fee"=>$open_fee,
  795. "pakge_fee"=>$pakge_fee,
  796. "nake_fee"=>$nake_fee,
  797. "mark_fee"=>$mark_fee,
  798. "cert_fee"=>$cert_fee,
  799. "cost_fee"=>$cost_fee,
  800. "total_fee"=>$total_fee,
  801. "supply_area"=>$supply_area,
  802. "remark"=>$remark,
  803. "sale_price"=>$saleprice,
  804. "sale_cost_fee"=>$sale_cost_fee,
  805. "origin_cost_fee"=>$sale_cost_fee,
  806. "origin_price"=>$saleprice,
  807. "createrid"=>$createrid,
  808. "creater"=>$creater,
  809. "status"=>$zxinfo['status']==1 ?1 :2,
  810. "is_del"=>0,
  811. "addtime"=>date("Y-m-d H:i:s"),
  812. "updatetime"=>date("Y-m-d H:i:s"),
  813. 'delivery_place'=>$delivery_place,//发货地
  814. 'cgder' => $supplier['person'] ?? '',
  815. 'cgderid' => $supplier['personid'] ?? 0,
  816. ];
  817. Db::startTrans();
  818. try{
  819. $insert= Db::name("consult_bids")->insert($data);
  820. if($insert){
  821. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  822. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  823. if($projectinfo==false){
  824. Db::rollback();
  825. return error_show(1006,"未找到项目信息");
  826. }
  827. $temp=[];
  828. $temp['spuCode']=$spucode;
  829. $temp['skuCode']="";
  830. $temp['pgNo']=$zxinfo['pgNo'];
  831. $temp['projectNo']=$zx['projectNo'];
  832. $temp['good_name']=$pname;
  833. $temp['good_type']=$projectinfo['good_type'];
  834. $temp['data_source']=2;
  835. $temp['cat_id']=$cat_id;
  836. $temp['budget_price']=$projectinfo['budget_price'];
  837. $temp['sale_price']=$saleprice;
  838. $temp['origin_price']=$total_fee;
  839. $temp['num']=$zxinfo['num'];
  840. $temp['status']=0;
  841. $temp['is_del']=0;
  842. $temp['creater']=$creater;
  843. $temp['createrid']=$createrid;
  844. $temp['addtime']=date("Y-m-d H:i:s");
  845. $temp['updatetime']=date("Y-m-d H:i:s");
  846. $nu = Db::name("project_feedback")->insert($temp);
  847. if($nu==false){
  848. Db::rollback();
  849. return error_show(1006,"项目反馈失败");
  850. }else{
  851. $old_projectinfo_status = $projectinfo['status'];
  852. $projectinfo['status']=2;
  853. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  854. $up = Db::name("project_info")->save($projectinfo);
  855. if($up){
  856. //修改状态,添加待办,只记录动作
  857. ActionLog::logAdd($this->post['token'], [
  858. "order_code" => $projectinfo['pgNo'],//编码
  859. "status" => $old_projectinfo_status,//这里的status是之前的值
  860. "action_remark" => '',//备注
  861. "action_type" => "status"//新建create,编辑edit,更改状态status
  862. ], "PRI", 2, $projectinfo);
  863. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  864. ->count();
  865. if($count==0){
  866. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  867. if($projetc!=false){
  868. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  869. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  870. if($proc==false){
  871. Db::rollback();
  872. return error_show(1006,"项目反馈失败");
  873. }else{
  874. //修改状态,添加待办
  875. ActionLog::logAdd($this->post['token'], [
  876. "order_code" => $projetc['projectNo'],//项目编码
  877. "status" => 1,//这里的status是之前的值
  878. "action_remark" => '',//备注
  879. "action_type" => "status"//新建create,编辑edit,更改状态status
  880. ], "PRO", 2, $projetc);
  881. ProcessOrder::AddProcess($this->post['token'], [
  882. "order_type" => 'PRO',
  883. "order_code" => $projetc['projectNo'],
  884. "order_id" => $projetc['id'],
  885. "order_status" => 2,"before_status"=>1
  886. ]);
  887. }
  888. }
  889. }
  890. }
  891. }
  892. }
  893. Db::commit();
  894. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  895. }else{
  896. Db::rollback();
  897. return error_show(1006,"反馈失败");
  898. }
  899. }catch (\Exception $e){
  900. Db::rollback();
  901. return error_show(1006,$e->getMessage());
  902. }
  903. }
  904. //反馈商品详情
  905. public function feadinfo(){
  906. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  907. if($bidNo==""){
  908. return error_show(1004,"参数bidNo不能为空");
  909. }
  910. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  911. if($info==false){
  912. return error_show(1004,"未找到商品数据");
  913. }
  914. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  915. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  916. $info['cat_info'] = made($info['cat_id'],[]);
  917. $info['noble_weight'] = $info['good_weight'];
  918. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  919. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  920. if($info['brand_id']!=0){
  921. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  922. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  923. }else{
  924. $info["brand_name"]="";
  925. $info["brand_id"]="";
  926. }
  927. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  928. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  929. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  930. $god=[
  931. "metal_id"=>$info['metal_id'],
  932. "weight"=>$info["good_weight"],
  933. "demo_fee"=>$info["demo_fee"],
  934. "delivery_fee"=>$info["delivery_fee"],
  935. "open_fee"=>$info["open_fee"],
  936. "packing_fee"=>$info["pakge_fee"],
  937. "mark_fee"=>$info["mark_fee"],
  938. "nake_fee"=>$info["nake_fee"],
  939. "cert_fee"=>$info["cert_fee"],
  940. "cost_fee"=>$info["cost_fee"],
  941. "num"=>$bidinfo["num"],
  942. ];
  943. if($info['is_gold_price']==1){
  944. $price = GoldPrice($god, $budget/100);
  945. $info['sale_price'] =round($price,2);
  946. }
  947. $info['specinfo'] = json_decode($info['specinfo'],true);
  948. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  949. if($info['delivery_place']!=""){
  950. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  951. }
  952. $info['delivery_place_cn']=GetAddr(json_encode($place));
  953. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  954. if($info['origin_place']!=""){
  955. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  956. }
  957. $info['origin_place_cn']=GetAddr(json_encode($place));
  958. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  959. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  960. $info['bargain'] =$bargain;
  961. $info['good_img'] = explode(',',$info['good_img']);
  962. //添加商品创建人字段
  963. $good_info = Db::name('good_basic')
  964. ->field('id,createrid,creater')
  965. ->where('is_del',0)
  966. ->where('spuCode',$info['spuCode'])
  967. ->findOrEmpty();
  968. $info['good_createrid'] = $good_info['createrid']??0;
  969. $info['good_creater'] = $good_info['creater']??'';
  970. return app_show(0,"获取成功",$info);
  971. }
  972. //反馈商品编辑
  973. public function feededit(){
  974. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  975. if($bidNo==""){
  976. return error_show(1002,"参数bidNo不能为空");
  977. }
  978. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  979. if($bidinfo==false){
  980. return error_show(1003,"未找到信息数据");
  981. }
  982. if($bidinfo['status']>=5){
  983. return error_show(1004,"咨询单已确认无法修改");
  984. }
  985. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  986. if($zxinfo==false){
  987. return error_show(1003,"未找到信息数据");
  988. }
  989. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  990. if($zx==false){
  991. return error_show(1003,"未找咨询信息数据");
  992. }
  993. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  994. if($pname==""){
  995. return error_show(1002,"参数pname不能为空");
  996. }
  997. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  998. // if($brandid==""){
  999. // return error_show(1002,"参数brandid不能为空");
  1000. // }
  1001. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1002. if($cat_id==""){
  1003. return error_show(1002,"参数cat_id不能为空");
  1004. }
  1005. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1006. if($specin==""){
  1007. return error_show(1003,"参数specinfo不能为空");
  1008. }
  1009. $specinfo=[];
  1010. foreach ($specin as $v){
  1011. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1012. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1013. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1014. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1015. $specinfo[]=$v;
  1016. }
  1017. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1018. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1019. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1020. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1021. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1022. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1023. :"";
  1024. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1025. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1026. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1027. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1028. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1029. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1030. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1031. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1032. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1033. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1034. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1035. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1036. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1037. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1038. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1039. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1040. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1041. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1042. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1043. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1044. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1045. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1046. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1047. if($delivery_place==''){
  1048. return error_show(1002,"参数delivery_place不能为空");
  1049. }
  1050. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1051. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1052. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1053. $cat_top_list = made($cat_id);
  1054. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1055. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1056. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1057. ->find();
  1058. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1059. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1060. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1061. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1062. $saleprice = $total_fee / (1 - $budget);
  1063. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1064. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1065. }else{
  1066. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1067. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1068. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1069. }
  1070. Db::startTrans();
  1071. try{
  1072. $data=[
  1073. "good_name"=>$pname,
  1074. "brand_id"=>$brandid,
  1075. "cat_id"=>$cat_id,
  1076. "specinfo"=>json_encode($specinfo),
  1077. // "material"=>$material,
  1078. "unit_id"=>$unit_id,
  1079. "cost_desc"=>$cost_desc,
  1080. "work_day"=>$work_day,
  1081. "delivery_day"=>$delivery_day,
  1082. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1083. "expire_day"=>$expire_day,
  1084. "origin_place"=>$origin_place,
  1085. "supplierNo"=>$supplierNo,
  1086. "pay_way"=>$pay_way,
  1087. "tax"=>$tax,
  1088. "send_way"=>$send_way,
  1089. "metal_id"=>$metal_id,
  1090. "is_gold_price"=>$is_gold_price,
  1091. "config"=>$config,
  1092. "other_config"=>$other_config,
  1093. "weight"=>$weight,
  1094. "good_weight"=>$noble_weight,
  1095. "is_diff"=>$is_diff,
  1096. "demo_fee"=>$demo_fee,
  1097. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1098. "delivery_fee"=>$delivery_fee,
  1099. "open_fee"=>$open_fee,
  1100. "pakge_fee"=>$pakge_fee,
  1101. "nake_fee"=>$nake_fee,
  1102. "mark_fee"=>$mark_fee,
  1103. "cert_fee"=>$cert_fee,
  1104. "cost_fee"=>$cost_fee,
  1105. "sale_cost_fee"=>$sale_cost_fee,
  1106. "origin_cost_fee"=>$sale_cost_fee,
  1107. "total_fee"=>$total_fee,
  1108. "sale_price"=>$saleprice,
  1109. "origin_price"=>$saleprice,
  1110. "supply_area"=>$supply_area,
  1111. "remark"=>$remark,
  1112. "status"=>0,
  1113. "updatetime"=>date("Y-m-d H:i:s"),
  1114. 'delivery_place' => $delivery_place
  1115. ];
  1116. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1117. if($insert){
  1118. if($zxinfo['bargain_status']==1){
  1119. $zxinfo['bargain_status']=0;
  1120. $infoip =Db::name("consult_info")->save($zxinfo);
  1121. if($infoip==false){
  1122. Db::rollback();
  1123. return error_show(1006,"咨询信息状态更新失败");
  1124. }
  1125. }
  1126. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1127. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1128. if($projectinfo==false){
  1129. Db::rollback();
  1130. return error_show(1006,"未找到项目信息");
  1131. }
  1132. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1133. if($feed!=false) {
  1134. $feed['good_name']=$pname;
  1135. $feed['good_type']=$projectinfo['good_type'];
  1136. $feed['cat_id']=$cat_id;
  1137. $feed['sale_price']=$saleprice;
  1138. $feed['origin_price']=$total_fee;
  1139. $feed['updatetime']=date("Y-m-d H:i:s");
  1140. $temp['updatetime']=date("Y-m-d H:i:s");
  1141. $nu=Db::name("project_feedback")->save($feed);
  1142. if ($nu == false) {
  1143. Db::rollback();
  1144. return error_show(1006 , "项目反馈失败");
  1145. } else {
  1146. $old_projectinfo_status=$projectinfo['status'];
  1147. $projectinfo['status']=2;
  1148. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1149. $up=Db::name("project_info")->save($projectinfo);
  1150. if ($up) {
  1151. //修改状态,添加待办,只记录动作
  1152. ActionLog::logAdd($this->post['token'] , [
  1153. "order_code"=>$projectinfo['pgNo'] ,//编码
  1154. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1155. "action_remark"=>'' ,//备注
  1156. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1157. ] , "PRI" , 2 , $projectinfo
  1158. );
  1159. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1160. if ($count == 0) {
  1161. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1162. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1163. if ($project_id) {
  1164. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1165. if ($proc == false) {
  1166. Db::rollback();
  1167. return error_show(1006 , "项目反馈失败");
  1168. } else {
  1169. //修改状态,添加待办
  1170. ActionLog::logAdd($this->post['token'] , [
  1171. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1172. "status"=>1 ,//这里的status是之前的值
  1173. "action_remark"=>'' ,//备注
  1174. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1175. ] , "PRO" , 2 , $this->post
  1176. );
  1177. ProcessOrder::AddProcess($this->post['token'] , [
  1178. "order_type"=>'PRO' ,
  1179. "order_code"=>$projectinfo['projectNo'] ,
  1180. "order_id"=>$project_id ,
  1181. "order_status"=>2 , "before_status"=>1
  1182. ]
  1183. );
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. Db::commit();
  1192. return app_show(0,"编辑成功");
  1193. }else{
  1194. Db::rollback();
  1195. return error_show(1004,"编辑失败");
  1196. }
  1197. }catch (\Exception $e){
  1198. Db::rollback();
  1199. return error_show(1004,$e->getMessage());
  1200. }
  1201. }
  1202. //生成议价单
  1203. public function bargain_add(){
  1204. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1205. if($bidNo===""){
  1206. return error_show(1004,"参数bidNo不能为空");
  1207. }
  1208. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1209. if($info==false){
  1210. return error_show(1004,"未找到商品数据");
  1211. }
  1212. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1213. if($consult==false){
  1214. return error_show(1004,"未找到咨询数据");
  1215. }
  1216. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1217. if($bargain_price===""){
  1218. return error_show(1004,"参数bargain_price不能为空");
  1219. }
  1220. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1221. if($info['is_gold_price']==1){
  1222. if($cost_price==""){
  1223. return error_show(1004,"参数cost_price不能为空");
  1224. }
  1225. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1226. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1227. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1228. ->find();
  1229. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1230. }
  1231. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1232. // if($bargain_reason===""){
  1233. // return error_show(1004,"参数bargain_reason不能为空");
  1234. // }
  1235. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1236. if($infos==false){
  1237. return error_show(1004,"未找到商品数据");
  1238. }
  1239. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1240. return error_show(1004,"咨询单招标未结束或已确认商品");
  1241. }
  1242. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1243. if($token==''){
  1244. return error_show(105,"参数token不能为空");
  1245. }
  1246. $user =GetUserInfo($token);
  1247. if(empty($user)||$user['code']!=0){
  1248. return error_show(1002,"用户数据不存在");
  1249. }
  1250. //新增两个字段
  1251. //议价备注
  1252. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1253. //议价原因id
  1254. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1255. if ($result_info_id != '') {
  1256. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1257. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1258. }
  1259. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1260. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1261. $bargainNo =makeNo("BA");
  1262. Db::startTrans();//::todo 金价 毛利计算
  1263. try{
  1264. $data=[
  1265. "bidsNo"=>$bidNo,
  1266. "infoNo"=>$info['infoNo'],
  1267. "zxNo"=>$info['zxNo'],
  1268. "bargainNo"=>$bargainNo,
  1269. "bargain_type"=>1,
  1270. "bargain_reason"=>$bargain_reason,
  1271. "sale_price"=>$info['sale_price'],
  1272. "cost_before_price"=>$info['sale_cost_fee'],
  1273. "cost_after_price"=>$cost_price,
  1274. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1275. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1276. "after_price"=>$bargain_price,
  1277. "exam_info"=>"",
  1278. "status"=>0,
  1279. "is_del"=>0,
  1280. "creater"=>$creater,
  1281. "createrid"=>$createrid,
  1282. "addtime"=>date("Y-m-d H:i:s"),
  1283. "updatetime"=>date("Y-m-d H:i:s"),
  1284. 'bargain_remark'=>$bargain_remark,
  1285. 'result_info_id'=>$result_info_id,
  1286. ];
  1287. $int = Db::name("bargain_order")->insertGetId($data);
  1288. if($int){
  1289. //修改状态,添加待办
  1290. ActionLog::logAdd($this->post['token'], [
  1291. "order_code" => $bargainNo,//咨询单详情编号
  1292. "status" => 0,//这里的status是之前的值
  1293. "action_remark" => '',//备注
  1294. "action_type" => "status"//新建create,编辑edit,更改状态status
  1295. ], "YJD", $data['status'], $data);
  1296. ProcessOrder::AddProcess($this->post['token'], [
  1297. "order_type" => 'YJD',
  1298. "order_code" => $bargainNo,
  1299. "order_id" => $int,
  1300. "order_status" =>0,
  1301. "before_status"=>0,
  1302. 'holder_id'=>$data['createrid']
  1303. ]);
  1304. $odlstatus=$info['status'];
  1305. $info['status']=3;
  1306. $info['updatetime']=date("Y-m-d H:i:s");
  1307. $up =Db::name("consult_bids")->save($info);
  1308. if($up){
  1309. //修改状态,添加待办
  1310. ActionLog::logAdd($this->post['token'], [
  1311. "order_code" => $bidNo,//咨询单详情编号
  1312. "status" => $odlstatus,//这里的status是之前的值
  1313. "action_remark" => '',//备注
  1314. "action_type" => "status"//新建create,编辑edit,更改状态status
  1315. ], "FKD", $info['status'], $info);
  1316. $old_infos_status = $infos['status'];
  1317. $infos['status']=3;
  1318. $infos['updatetime']=date("Y-m-d H:i:s");
  1319. $ups =Db::name("consult_info")->save($infos);
  1320. if($ups){
  1321. //修改状态,添加待办
  1322. ActionLog::logAdd($this->post['token'], [
  1323. "order_code" => $infos['infoNo'],//咨询单详情编号
  1324. "status" => $old_infos_status,//这里的status是之前的值
  1325. "action_remark" => '',//备注
  1326. "action_type" => "status"//新建create,编辑edit,更改状态status
  1327. ], "ZXD", $infos['status'], $infos);
  1328. //维护台账信息
  1329. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1330. Db::commit();
  1331. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1332. }
  1333. }
  1334. }
  1335. Db::rollback();
  1336. return error_show(1004,"议价单新建失败");
  1337. }catch (\Exception $e){
  1338. Db::rollback();
  1339. return error_show(1004,$e->getMessage());
  1340. }
  1341. }
  1342. //选择商品
  1343. public function bids_check(){
  1344. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1345. if($bidNo===""){
  1346. return error_show(1004,"参数bidNo不能为空");
  1347. }
  1348. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1349. if($info==false){
  1350. return error_show(1004,"未找到商品数据");
  1351. }
  1352. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1353. if($infos==false){
  1354. return error_show(1004,"未找到商品数据");
  1355. }
  1356. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1357. return error_show(1004,"咨询单招标未结束或已确认商品");
  1358. }
  1359. Db::startTrans();
  1360. try {
  1361. $oldstattus=$info['status'];
  1362. $info['status']=6;
  1363. $info['updatetime']=date("Y-m-d H:i:s");
  1364. $bids = Db::name("consult_bids")->save($info);
  1365. if($bids){
  1366. //修改状态,添加待办
  1367. ActionLog::logAdd($this->post['token'], [
  1368. "order_code" =>$bidNo,//咨询单详情编号
  1369. "status" => $oldstattus,//这里的status是之前的值
  1370. "action_remark" => '',//备注
  1371. "action_type" => "status"//新建create,编辑edit,更改状态status
  1372. ], "FKD", $info['status'], $info);
  1373. $old_infos_status = $infos['status'];
  1374. $infos['status']=4;
  1375. $infos['updatetime']=date("Y-m-d H:i:s");
  1376. $se = Db::name("consult_info")->save($infos);
  1377. if($se){
  1378. //修改状态,添加待办
  1379. ActionLog::logAdd($this->post['token'], [
  1380. "order_code" => $infos['infoNo'],//咨询单详情编号
  1381. "status" => $old_infos_status,//这里的status是之前的值
  1382. "action_remark" => '',//备注
  1383. "action_type" => "status"//新建create,编辑edit,更改状态status
  1384. ], "ZXD", $infos['status'], $infos);
  1385. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1386. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1387. Db::commit();
  1388. return app_show(0,"商品确定成功");
  1389. }
  1390. }
  1391. Db::rollback();
  1392. return error_show(1004,"商品确认失败");
  1393. }catch (\Exception $e){
  1394. Db::rollback();
  1395. return error_show(1004,$e->getMessage());
  1396. }
  1397. }
  1398. //议价审核
  1399. /**
  1400. * status:
  1401. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1402. */
  1403. public function bargain_status(){
  1404. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1405. if($bargainNo===""){
  1406. return error_show(1004,"参数bargainNo不能为空");
  1407. }
  1408. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1409. if($info==false){
  1410. return error_show(1004,"未找到议价数据");
  1411. }
  1412. if($info['status']==12){
  1413. return error_show(1004,"议价单已取消");
  1414. }
  1415. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1416. if($bids==false){
  1417. return error_show(1004,"未找到商品数据");
  1418. }
  1419. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1420. if($coninfo==false){
  1421. return error_show(1004,"未找到咨询单数据");
  1422. }
  1423. if($bids['status']==6){
  1424. return error_show(1004,"咨询已选择商品");
  1425. }
  1426. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1427. if($status===''){
  1428. return error_show(1005,"参数status不能为空");
  1429. }
  1430. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1431. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1432. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1433. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1434. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1435. if($bids['is_gold_price']==1){
  1436. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1437. ->find();
  1438. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1439. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1440. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1441. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1442. $saleprice =$total_fe / (1 - $budget);
  1443. $rate_price = $total_fe / (1 - $rate);
  1444. $money_price =$total_fe / (1 - $money_rate);
  1445. $lower_price =$total_fe / (1 - $lower_rate);
  1446. }else{
  1447. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1448. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1449. if($bids['nake_fee']!=0){
  1450. $saleprice = ($total_fe)/ (1 - $budget);
  1451. $rate_price = ($total_fe)/ (1 - $rate);
  1452. $money_price =($total_fe)/ (1 - $money_rate);
  1453. $lower_price = ($total_fe) / (1 - $lower_rate);
  1454. }else{
  1455. $saleprice = $total_fe / (1 - $budget);
  1456. $rate_price =$total_fe/ (1 - $rate);
  1457. $money_price =$total_fe / (1 - $money_rate);
  1458. $lower_price = $total_fe/ (1 - $lower_rate);
  1459. }
  1460. }
  1461. $ra_status = $info['status'];
  1462. if($status==1){
  1463. if($info['status']==0){
  1464. if($info['after_price']<$rate_price){
  1465. $info['status']=2;
  1466. }else{
  1467. $info['status']=1;
  1468. }
  1469. }elseif($info['status']==2){
  1470. $info['status']=4;
  1471. }elseif($info['status']==4||$info['status']==5){
  1472. if($info['after_price']<$money_price){
  1473. $info['status']=7;
  1474. }else{
  1475. $info['status']=6;
  1476. }
  1477. }elseif($info['status']==7){
  1478. $info['lower_price'] =$lower_price;
  1479. if($info['after_price']<$lower_price){
  1480. $info['status']=10;
  1481. }else{
  1482. $info['status']=9;
  1483. }
  1484. }
  1485. }else{
  1486. if($info['status']==0){
  1487. $info['status']=3;
  1488. }elseif($info['status']==2){
  1489. $info['status']=4;
  1490. }elseif($info['status']==4||$info['status']==5){
  1491. $info['status']=8;
  1492. }elseif($info['status']==7){
  1493. $info['lower_price'] =$lower_price;
  1494. $info['status']=11;
  1495. }
  1496. }
  1497. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1498. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1499. if($token==''){
  1500. return error_show(105,"参数token不能为空");
  1501. }
  1502. $user =GetUserInfo($token);
  1503. if(empty($user)||$user['code']!=0){
  1504. return error_show(1002,"用户数据不存在");
  1505. }
  1506. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1507. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1508. Db::startTrans();
  1509. try{
  1510. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1511. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1512. "creater"=>$creater];
  1513. // $info['status'] =$status;
  1514. $info['remark'] =$remark;
  1515. $info['exam_info']=json_encode($examinfo) ;
  1516. $info['updatetime'] =date("Y-m-d H:i:s");
  1517. $up =Db::name("bargain_order")->save($info);
  1518. if($up){
  1519. //修改状态,添加待办
  1520. ActionLog::logAdd($this->post['token'], [
  1521. "order_code" => $bargainNo,//咨询单详情编号
  1522. "status" =>$ra_status,//这里的status是之前的值
  1523. "action_remark" => '',//备注
  1524. "action_type" => "status"//新建create,编辑edit,更改状态status
  1525. ], "YJD", $info['status'], $info);
  1526. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
  1527. ProcessOrder::AddProcess($token,$process);
  1528. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1529. $bidstatus=$bids['status'];
  1530. $bids['status']=5;
  1531. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1532. $bids['sale_price']=$info['after_price'];
  1533. if($bids['is_gold_price']==1){
  1534. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1535. // ->find();
  1536. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1537. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1538. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1539. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1540. }
  1541. }
  1542. $bids['updatetime']=date("Y-m-d H:i:s");
  1543. $up =Db::name("consult_bids")->save($bids);
  1544. if($up==false){
  1545. Db::rollback();
  1546. return error_show(1004,"数据更新失败");
  1547. }
  1548. ActionLog::logAdd($this->post['token'], [
  1549. "order_code" => $info["bidsNo"],//咨询单详情编号
  1550. "status" => $bidstatus,//这里的status是之前的值
  1551. "action_remark" => '',//备注
  1552. "action_type" => "status"//新建create,编辑edit,更改状态status
  1553. ], "FKD", $bids['status'], $bids);
  1554. }
  1555. Db::commit();
  1556. return app_show(0,"更新成功");
  1557. }
  1558. }catch (\Exception $e){
  1559. Db::rollback();
  1560. return error_show(1004,$e->getMessage());
  1561. }
  1562. }
  1563. public function bargain_info(){
  1564. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1565. if($bargainNo===""){
  1566. return error_show(1004,"参数bargainNo不能为空");
  1567. }
  1568. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1569. if($info==false){
  1570. return error_show(1004,"未找到议价数据");
  1571. }
  1572. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1573. if($bidinfos==false){
  1574. return error_show(1004,"未找到商品数据");
  1575. }
  1576. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1577. if($consultinfos==false){
  1578. return error_show(1004,"未找到咨询商品数据");
  1579. }
  1580. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1581. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1582. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1583. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1584. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1585. $info['before_rate'] =round($info['before_rate']*100,2);
  1586. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1587. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1588. $info['after_rate'] = round($info['after_rate']*100,2);
  1589. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1590. if($bidinfos['brand_id']!=0){
  1591. $info['brand_id'] = $bidinfos['brand_id'];
  1592. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1593. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1594. }else{
  1595. $info["brand_name"]="";
  1596. $info["brand_id"]="";
  1597. }
  1598. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1599. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1600. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1601. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1602. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1603. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1604. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1605. $info['budget'] =$budget;
  1606. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1607. if($info['after_rate']>=$catinfo['rate']){
  1608. //业务主管利率
  1609. $info['rate_status'] =1;
  1610. }
  1611. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1612. //财务主管利率
  1613. $info['rate_status'] =2;
  1614. }
  1615. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1616. //boss利率
  1617. $info['rate_status'] =3;
  1618. }
  1619. $god=[
  1620. "metal_id"=>$bidinfos['metal_id'],
  1621. "weight"=>$bidinfos["good_weight"],
  1622. "demo_fee"=>$bidinfos["demo_fee"],
  1623. "delivery_fee"=>$bidinfos["delivery_fee"],
  1624. "open_fee"=>$bidinfos["open_fee"],
  1625. "packing_fee"=>$bidinfos["pakge_fee"],
  1626. "mark_fee"=>$bidinfos["mark_fee"],
  1627. "nake_fee"=>$bidinfos["nake_fee"],
  1628. "cert_fee"=>$bidinfos["cert_fee"],
  1629. "cost_fee"=>$bidinfos["cost_fee"],
  1630. "num"=>$bidinfoe["num"],
  1631. ];
  1632. $info['gold_price']=0;
  1633. $info['noble_weight']=$bidinfos['good_weight'];
  1634. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1635. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1636. ->find();
  1637. $info['gold_price'] =$gold['price'];
  1638. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1639. }else{
  1640. if($bidinfos['nake_fee']!=0){
  1641. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1642. }else{
  1643. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1644. }
  1645. }
  1646. $info['cost_desc'] =$bidinfos['cost_desc'];
  1647. $info['work_day'] =$bidinfos['work_day'];
  1648. $info['delivery_day'] =$bidinfos['delivery_day'];
  1649. $info['expire_day'] =$bidinfos['expire_day'];
  1650. $info['origin_place'] =$bidinfos['origin_place'];
  1651. $info['origin_addr'] ="";
  1652. if($bidinfos['origin_place']!=''){
  1653. $code = explode(",",$bidinfos['origin_place']);
  1654. $temp=[];
  1655. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1656. $temp['city_code']=isset($code[1])?$code[1]:"";
  1657. $temp['area_code']=isset($code[2])?$code[2]:"";
  1658. $addr= GetAddr(json_encode($temp));
  1659. $info['origin_addr'] = $addr;
  1660. }
  1661. $info['supplierNo'] =$bidinfos['supplierNo'];
  1662. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1663. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1664. $info['pay_way'] =$bidinfos['pay_way'];
  1665. $info['tax'] =$bidinfos['tax'];
  1666. $info['send_way'] =$bidinfos['send_way'];
  1667. $info['metal_id'] =$bidinfos['metal_id'];
  1668. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1669. $info['config'] =$bidinfos['config'];
  1670. $info['other_config'] =$bidinfos['other_config'];
  1671. $info['weight'] =$bidinfos['weight'];
  1672. $info['good_weight'] =$bidinfos['good_weight'];
  1673. $info['is_diff'] =$bidinfos['is_diff'];
  1674. $info['demo_fee'] =$bidinfos['demo_fee'];
  1675. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1676. $info['open_fee'] =$bidinfos['open_fee'];
  1677. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1678. $info['nake_fee'] =$bidinfos['nake_fee'];
  1679. $info['mark_fee'] =$bidinfos['mark_fee'];
  1680. $info['cert_fee'] =$bidinfos['cert_fee'];
  1681. $info['cost_fee'] =$bidinfos['cost_fee'];
  1682. $info['total_fee'] =$bidinfos['total_fee'];
  1683. $info['supply_area'] =$bidinfos['supply_area'];
  1684. $info['remark'] =$bidinfos['remark'];
  1685. $info['is_addrs'] =$consultinfos['is_addrs'];
  1686. $info['is_custom'] =$consultinfos['is_custom'];
  1687. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1688. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1689. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1690. if($info['status']==7){
  1691. $info['lower_price'] =round($lower_price,2);
  1692. }
  1693. //获取议价原因
  1694. if ($info['result_info_id'] != 0) {
  1695. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1696. } else {
  1697. $info['result_info'] = '';
  1698. }
  1699. return app_show(0,"获取成功",$info);
  1700. }
  1701. public function bidlist(){
  1702. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1703. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1704. $where=[['is_del',"=",0]];
  1705. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1706. if ($zxNo !== "") {
  1707. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1708. }
  1709. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1710. if ($infoNo !== "") {
  1711. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1712. }
  1713. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1714. if ($bidNo !== "") {
  1715. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1716. }
  1717. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1718. if ($pgNo !== "") {
  1719. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1720. $where[] = ['infoNo','in',$bidinfo];
  1721. }
  1722. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1723. if ($bargain_status !== "") {
  1724. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1725. $where[] = ['infoNo','in',$bidinfo];
  1726. }
  1727. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1728. if ($projectNo !== "") {
  1729. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1730. ("zxNo");
  1731. $where[] = ['zxNo','in',$zxlist];
  1732. }
  1733. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1734. if($is_own==1){
  1735. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1736. if($token==""){
  1737. return error_show(101,'token不能为空');
  1738. }
  1739. $apply_id =GetUserInfo($token);
  1740. if(empty($apply_id)||$apply_id['code']!=0){
  1741. return error_show(1002,"申请人数据不存在");
  1742. }
  1743. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1744. $where[]=['createrid',"=",$rm];
  1745. }
  1746. $count = Db::name('consult_bids')->where($where)->count();
  1747. $total = ceil($count / $size);
  1748. $page = $page >= $total ? $total : $page;
  1749. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1750. $data=[];
  1751. foreach ($list as $value){
  1752. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1753. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1754. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1755. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1756. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1757. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1758. if($value['brand_id']!=0){
  1759. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1760. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1761. }else{
  1762. $value["brand_name"]="";
  1763. $value["brand_id"]="";
  1764. }
  1765. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1766. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1767. $god=[
  1768. "metal_id"=>$value['metal_id'],
  1769. "weight"=>$value["good_weight"],
  1770. "demo_fee"=>$value["demo_fee"],
  1771. "delivery_fee"=>$value["delivery_fee"],
  1772. "open_fee"=>$value["open_fee"],
  1773. "packing_fee"=>$value["pakge_fee"],
  1774. "mark_fee"=>$value["mark_fee"],
  1775. "nake_fee"=>$value["nake_fee"],
  1776. "cert_fee"=>$value["cert_fee"],
  1777. // "cost_fee"=>$value["cost_fee"],
  1778. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1779. //暂时注掉,搞不清楚原因@吴广广
  1780. "num"=>$bidinfo["num"],
  1781. ];
  1782. $top_cat = made($value['cat_id']);
  1783. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1784. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1785. $price = GoldPrice($god, $budget/100);
  1786. $value['sale_price'] = round($price,2);
  1787. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1788. $value["origin_price"];
  1789. }
  1790. $value['cost_fee'] =$value['origin_cost_fee'];
  1791. $value['specinfo'] = json_decode($value['specinfo'],true);
  1792. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1793. $value['bargain_status']=$bidinfo['bargain_status'];
  1794. //reject驳回原因,status==5表示驳回
  1795. $value['reject']=[];
  1796. if ($value['status'] >=5) {
  1797. $value['reject'] = Db::name('bargain_order')
  1798. ->field('id,remark,status')
  1799. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1800. ->whereIn('status', [3,8,11])->order("id desc")
  1801. ->find();
  1802. }
  1803. //产地
  1804. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1805. if($value['delivery_place']!=""){
  1806. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1807. }
  1808. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1809. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1810. if($value['origin_place']!=""){
  1811. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1812. }
  1813. $value['origin_addr']=GetAddr(json_encode($place));
  1814. // if($value['origin_place']!=''){
  1815. // $code = explode(",",$value['origin_place']);
  1816. // $temp=[];
  1817. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1818. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1819. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1820. // $addr= GetAddr(json_encode($temp));
  1821. // $value['origin_addr'] = $addr;
  1822. // }
  1823. $good_info = Db::name('good_basic')
  1824. ->field('id,createrid,creater')
  1825. ->where('is_del',0)
  1826. ->where('spuCode',$value['spuCode'])
  1827. ->findOrEmpty();
  1828. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1829. $value['good_creater']=$good_info['creater']??$value['creater'];
  1830. $data[] = $value;
  1831. }
  1832. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1833. }
  1834. public function feedlist(){
  1835. $where=[['is_del',"=",0]];
  1836. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1837. if ($zxNo !== "") {
  1838. $where[] = ['zxNo','=',$zxNo];
  1839. }
  1840. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1841. if ($infoNo !== "") {
  1842. $where[] = ['infoNo','=',$infoNo];
  1843. }
  1844. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1845. if ($bidNo !== "") {
  1846. $where[] = ['bidNo','=',$bidNo];
  1847. }
  1848. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1849. if ($projectNo !== "") {
  1850. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1851. ("zxNo");
  1852. $where[] = ['zxNo','in',$zxlist];
  1853. }
  1854. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1855. if($token==''){
  1856. return error_show(102,"参数token不能为空");
  1857. }
  1858. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1859. if($is_own==1){
  1860. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1861. if($token==""){
  1862. return error_show(101,'token不能为空');
  1863. }
  1864. $apply_id =GetUserInfo($token);
  1865. if(empty($apply_id)||$apply_id['code']!=0){
  1866. return error_show(1002,"申请人数据不存在");
  1867. }
  1868. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1869. $where[]=['createrid',"=",$rm];
  1870. }
  1871. $list =Db::name('consult_bids')->where($where)->select();
  1872. $data=[];
  1873. foreach ($list as $value){
  1874. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1875. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1876. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1877. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1878. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1879. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1880. if($value['brand_id']!=0){
  1881. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1882. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1883. }else{
  1884. $value["brand_name"]="";
  1885. $value["brand_id"]="";
  1886. }
  1887. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1888. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1889. $god=[
  1890. "metal_id"=>$value['metal_id'],
  1891. "weight"=>$value["good_weight"],
  1892. "demo_fee"=>$value["demo_fee"],
  1893. "delivery_fee"=>$value["delivery_fee"],
  1894. "open_fee"=>$value["open_fee"],
  1895. "packing_fee"=>$value["pakge_fee"],
  1896. "mark_fee"=>$value["mark_fee"],
  1897. "nake_fee"=>$value["nake_fee"],
  1898. "cert_fee"=>$value["cert_fee"],
  1899. "cost_fee"=>$value["cost_fee"],
  1900. "num"=>$bidinfo["num"],
  1901. ];
  1902. if ($value['is_gold_price'] == 1 ) {
  1903. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1904. ->find();
  1905. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1906. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1907. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1908. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1909. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1910. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1911. }else{
  1912. if($value["nake_fee"]){
  1913. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1914. }else{
  1915. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1916. (1 - $budget);
  1917. }
  1918. }
  1919. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1920. $value['specinfo'] = json_decode($value['specinfo'],true);
  1921. $value['bargain_status']=$bidinfo['bargain_status'];
  1922. $data[]=$value;
  1923. }
  1924. return app_show(0,"获取成功",$data);
  1925. }
  1926. public function bragain_list(){
  1927. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1928. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1929. $where=[['bo.is_del',"=",0]];
  1930. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1931. if($bidsNo!=""){
  1932. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1933. }
  1934. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1935. if ($zxNo !== "") {
  1936. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1937. }
  1938. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1939. if ($bargainNo !== "") {
  1940. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1941. }
  1942. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1943. if ($status!== "") {
  1944. $where[] = ['bo.status','=',$status];
  1945. }
  1946. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1947. if ($infoNo !== "") {
  1948. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1949. }
  1950. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1951. if ($projectNo !== "") {
  1952. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1953. $where[] = ['bo.zxNo','in',$zxlist];
  1954. }
  1955. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1956. if ($pgNo !== "") {
  1957. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1958. $where[] = ['bo.infoNo','in',$bidinfo];
  1959. }
  1960. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1961. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1962. if($start!=""){
  1963. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1964. }
  1965. if($end!=""){
  1966. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1967. }
  1968. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1969. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1970. // $role=$this->checkRole();
  1971. // if(!empty($role['write'])){
  1972. // $where[]=["bo.createrid","in",$role['write']];
  1973. // }
  1974. $role = $this->checkDataShare();
  1975. if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1976. $count=Db::name("bargain_order")
  1977. ->alias('bo')
  1978. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1979. ->where($where)
  1980. ->count();
  1981. $total = ceil($count / $size);
  1982. $page = $page >= $total ? $total : $page;
  1983. $list = Db::name('bargain_order')
  1984. ->alias('bo')
  1985. ->field('bo.*,u.itemid')
  1986. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1987. ->where($where)
  1988. ->page($page, $size)
  1989. ->order('bo.addtime', 'desc')
  1990. ->cursor();
  1991. $data=[];
  1992. foreach ($list as $value){
  1993. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1994. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1995. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1996. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1997. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1998. if($bidinfos['brand_id']!=0){
  1999. $value['brand_id'] = $bidinfos['brand_id'];
  2000. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2001. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2002. }else{
  2003. $value["brand_name"]="";
  2004. $value["brand_id"]="";
  2005. }
  2006. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2007. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2008. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2009. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2010. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2011. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2012. $value['budget'] =$budget;
  2013. $god=[
  2014. "metal_id"=>$bidinfos['metal_id'],
  2015. "weight"=>$bidinfos["good_weight"],
  2016. "demo_fee"=>$bidinfos["demo_fee"],
  2017. "delivery_fee"=>$bidinfos["delivery_fee"],
  2018. "open_fee"=>$bidinfos["open_fee"],
  2019. "packing_fee"=>$bidinfos["pakge_fee"],
  2020. "mark_fee"=>$bidinfos["mark_fee"],
  2021. "nake_fee"=>$bidinfos["nake_fee"],
  2022. "cert_fee"=>$bidinfos["cert_fee"],
  2023. "cost_fee"=>$bidinfos["cost_fee"],
  2024. "num"=>$bidinfoe["num"],
  2025. ];
  2026. // if($bidinfos['is_gold_price']==1){
  2027. // $price = GoldPrice($god, $budget/100);
  2028. // }else{
  2029. // $price = GoodPrice($god, $budget/100);
  2030. // }
  2031. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2032. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2033. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2034. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2035. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2036. //是否具有编辑权限
  2037. $value['is_allow_update'] = 0;
  2038. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2039. $data[]=$value;
  2040. }
  2041. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2042. }
  2043. public function crontablist(){
  2044. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2045. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2046. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2047. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2048. if ($zxNo !== "") {
  2049. $where[] = ['a.zxNo','=',$zxNo];
  2050. }
  2051. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2052. if ($salesman !== "") {
  2053. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2054. $where[]= ["b.salesman",'like',"%$salesman%"];
  2055. }
  2056. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2057. if ($cpName !== "") {
  2058. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2059. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2060. }
  2061. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2062. if ($khNo !== "") {
  2063. // $where['khNo'] = $khNo;
  2064. $where[]= ["b.khNo",'like',"%$khNo%"];
  2065. }
  2066. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2067. if ($start !="") {
  2068. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2069. $where[]= ["a.addtime",'>=',$start];
  2070. }
  2071. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2072. if($end !=""){
  2073. $where[]= ["a.addtime",'<=',$end];
  2074. }
  2075. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2076. if ($status !== "") {
  2077. $where[]= ["a.status",'=',$status];
  2078. }
  2079. // $role=$this->checkRole();
  2080. // if(!empty($role['platform']) ){
  2081. // $where[]=["b.platform_code","in",$role['platform']];
  2082. // }
  2083. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2084. ->count();
  2085. $total = ceil($count / $size);
  2086. $page = $page >= $total ? $total : $page;
  2087. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2088. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2089. $data=[];
  2090. foreach ($list as $value){
  2091. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2092. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2093. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2094. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2095. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2096. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2097. $value['khname']="";
  2098. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2099. true):[];
  2100. if($value['khNo']!==""){
  2101. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2102. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2103. }
  2104. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2105. ->find();
  2106. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2107. $value['is_feed'] =$consult==false?0:1;
  2108. $value['is_all_feed'] =$consults==false?0:1;
  2109. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2110. $data[]=$value;
  2111. }
  2112. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2113. }
  2114. //复制上面的bidlist方法,只更改排序方式
  2115. public function bidlistCopy()
  2116. {
  2117. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2118. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2119. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2120. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2121. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2122. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2123. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2124. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2125. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2126. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2127. if ($pgNo !== "") {
  2128. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2129. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2130. }
  2131. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2132. if ($bargain_status !== "") {
  2133. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2134. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2135. }
  2136. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2137. if ($projectNo !== "") {
  2138. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2139. $where[] = ['cb.zxNo', 'in', $zxlist];
  2140. }
  2141. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2142. if ($is_own == 1) {
  2143. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2144. if ($token == "") return error_show(101, 'token不能为空');
  2145. $apply_id = GetUserInfo($token);
  2146. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2147. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2148. $where[] = ['cb.createrid', "=", $rm];
  2149. }
  2150. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2151. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2152. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2153. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2154. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2155. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2156. $count = Db::name('consult_bids')
  2157. ->alias('cb')
  2158. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2159. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2160. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2161. ->where($where)
  2162. ->count();
  2163. $total = ceil($count / $size);
  2164. $page = $page >= $total ? $total : $page;
  2165. $list = Db::name('consult_bids')
  2166. ->alias('cb')
  2167. ->field('cb.*,u.itemid,s.name supplierName')
  2168. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2169. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2170. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2171. ->where($where)
  2172. ->page($page, $size)
  2173. ->order('cb.addtime', 'desc')
  2174. ->cursor();
  2175. $data = [];
  2176. foreach ($list as $value) {
  2177. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2178. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2179. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2180. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2181. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2182. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2183. if ($value['brand_id'] != 0) {
  2184. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2185. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2186. } else {
  2187. $value["brand_name"] = "";
  2188. $value["brand_id"] = "";
  2189. }
  2190. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2191. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2192. $god = [
  2193. "metal_id" => $value['metal_id'],
  2194. "weight" => $value["good_weight"],
  2195. "demo_fee" => $value["demo_fee"],
  2196. "delivery_fee" => $value["delivery_fee"],
  2197. "open_fee" => $value["open_fee"],
  2198. "packing_fee" => $value["pakge_fee"],
  2199. "mark_fee" => $value["mark_fee"],
  2200. "nake_fee" => $value["nake_fee"],
  2201. "cert_fee" => $value["cert_fee"],
  2202. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2203. "num" => $bidinfo["num"],
  2204. ];
  2205. if ($value['is_gold_price'] == 1) {
  2206. $price = GoldPrice($god, $budget / 100);
  2207. $value['sale_price'] = round($price, 2);
  2208. }
  2209. $value['cost_fee'] = $value['origin_cost_fee'];
  2210. $value['specinfo'] = json_decode($value['specinfo'], true);
  2211. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2212. $value['bargain_status'] = $bidinfo['bargain_status'];
  2213. //reject驳回原因,status==5表示驳回
  2214. $value['reject'] = [];
  2215. if ($value['status'] >= 5) {
  2216. $value['reject'] = Db::name('bargain_order')
  2217. ->field('id,remark,status')
  2218. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2219. ->whereIn('status', [3, 8, 11])->order("id desc")
  2220. ->find();
  2221. }
  2222. //产地
  2223. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2224. if ($value['delivery_place'] != "") {
  2225. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2226. }
  2227. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2228. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2229. if ($value['origin_place'] != "") {
  2230. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2231. }
  2232. $value['origin_addr'] = GetAddr(json_encode($place));
  2233. // if($value['origin_place']!=''){
  2234. // $code = explode(",",$value['origin_place']);
  2235. // $temp=[];
  2236. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2237. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2238. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2239. // $addr= GetAddr(json_encode($temp));
  2240. // $value['origin_addr'] = $addr;
  2241. // }
  2242. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2243. $data[] = $value;
  2244. }
  2245. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2246. }
  2247. }